Solved

how to send emails when records inserted?

Posted on 2002-03-06
3
257 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
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 142

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
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 backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now