Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to send emails when records inserted?

Posted on 2002-03-06
3
Medium Priority
?
264 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 200 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 200 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

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…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

664 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