I wish to use email functionality of sql to send me an email when an insert
is performed on a particular table. I know that a proc and may be a trigger
is required.
Can someone please provide me some hints.
Thanks,
GujuIt's not a good idea to send email from a trigger. Email is an
inherently asynchronous medium so there is really no need to hold open
a transaction while sending an email. Also, if the INSERT is performed
inside a transaction which later gets rolled back then the email will
have been sent for an INSERT that never actually happened.
Schedule a process that regularly checks for new rows and sends out
emails accordingly. For example you can use SQL Agent to call such a
process every minute if required.
More about emailing from SQL Server here:
http://www.aspfaq.com/show.asp?id=2403
--
David Portas
SQL Server MVP
--|||David,
What would the code look like in the proc?
Thanks,
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1109034627.228291.203650@.c13g2000cwb.googlegr oups.com...
> It's not a good idea to send email from a trigger. Email is an
> inherently asynchronous medium so there is really no need to hold open
> a transaction while sending an email. Also, if the INSERT is performed
> inside a transaction which later gets rolled back then the email will
> have been sent for an INSERT that never actually happened.
> Schedule a process that regularly checks for new rows and sends out
> emails accordingly. For example you can use SQL Agent to call such a
> process every minute if required.
> More about emailing from SQL Server here:
> http://www.aspfaq.com/show.asp?id=2403
> --
> David Portas
> SQL Server MVP
> --|||To call xp_sendmail? See Books Online for examples and syntax - there
are too many different options to cover here. I recommend
xp_smtp_sendmail instead - I've found it much easier to set up and more
reliable than xp_sendmail. Both are covered by the links in the article
I posted before.
--
David Portas
SQL Server MVP
--
No comments:
Post a Comment