Solved

how to send emails when records inserted?

Posted on 2002-03-06
3
259 Views
Last Modified: 2012-05-04
I like to send the email when the record in a table is inserted. the table will have the email address already.

should I use trigger in the table, never used it before, anyone provide some simple code to get me started.

yeah, i know, i will look into the sql help too, but i like to have people experience if i have problem understaning the sql help.

how to setup the email on the sql server as well.

Thanks
0
Comment
Question by:chrislee8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
meos earned 50 total points
ID: 6844922
you may use SQL built in SQL Mail with stored procedures: xp_sendmail; but also external utility (ie: sendmail.exe)

use triggers for table as:
--------------------------
CREATE TRIGGER reminder
ON titles
FOR INSERT
AS
   EXEC master..xp_sendmail 'MaryM',
      'Don''t forget to print a report for the distributors.'

--------------------------
or xp_cmdshell
--------------------------
CREATE TRIGGER reminder
ON titles
FOR INSERT
AS
   EXEC master..xp_cmdshell 'c:\sendmail.exe mary@hot.com "'Don''t forget to print a report for the distributors."'
--------------------------

hope it helps
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 50 total points
ID: 6846869
As meos indicates, using the xp_cmdshell inside the trigger is the "simple" solution.
However, this has some disadvantages:
* the insert statment will be delayed if any problems appear during the mail send
* the mail send cannot be tracked
* the mail send cannot easily be configured

Thus, i do not send the email directly, but insert a short record in a working table (like "TODO_SENDEMAIL_REMINDER"), with has only the ID fields to the related table, a timestamp field and a flag saying if the email has been send...
To send the emails, you can still use xp_cmdshell, by running a job for example, looping on that table. Of course, you can also use some other external process and mailing tools...

CHeers
0
 

Expert Comment

by:CleanupPing
ID: 9280792
chrislee8:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question