trigger to send Mail to an gmail or yahoo account

I want to create a trigger which executes the stored procedure

xp_sendmail or sp_send_dbmail. which one is correct.

By creating a trigger i need to send an email from the database and i am using sql server 2005.

'For this i used xp_sendmail but it is asking for parameter @user.

Kindly provide the detailed information how can i overcome these problems in sql server 2005 to send an email to a gmail or yahoo account using my trigger.

With Regards,


more ▼

asked Feb 23, 2010 at 03:35 AM in Default

avatar image

65 8 10 11

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

As you're on SQL 2005 you should use sp_send_dbmail. If you read the article Brimstedt linked to, you'll see that xp_sendmail is deprecated. It's only there for backwards compatibility.

more ▼

answered Feb 23, 2010 at 04:48 AM

avatar image

David Wimbush
10.7k 31 34 43

  • sp_send_dbmail is also much more reliable, configurable and doesnt require a SMTP Client (such as Outlook) to be installed on the server.

Feb 23, 2010 at 05:51 AM Fatherjack ♦♦

Could you specify me that how can i use this sp_send_dbmail in my trigger, while i am executing it is diplaying 'Mail queued', but mail wasn't delivered.why it is like this?

Feb 23, 2010 at 06:02 AM Damus

'Mail Queued' means that the email was succesfully added to the queue for processing - use sysmail_help_queue_sp to see what is being queued. Look at http://msdn.microsoft.com/en-us/library/ms190630(SQL.90).aspx or the same subject in BOL to help understand why your message isn't being delivered

Feb 23, 2010 at 06:08 AM Kev Riley ♦♦
(comments are locked)
10|1200 characters needed characters left

Here is a helpful link: http://lmgtfy.com/?q=xp_sendmail

From what i can see in documentation, there is no @user parameter. There is @set_user, but it is not mandatory.

The docs further says that xp-sendmail is great for use in triggers, so i guess you're on the right track: http://msdn.microsoft.com/en-us/library/ms189505.aspx

Perhaps posting the exact error message you get can help us help you.

more ▼

answered Feb 23, 2010 at 04:02 AM

avatar image

226 4 5 7

Halike it... +1 for the google link... Would like to +10 but it wont allow me ;-)

Feb 23, 2010 at 08:28 AM sp_lock
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Feb 23, 2010 at 03:35 AM

Seen: 3844 times

Last Updated: Feb 23, 2010 at 06:09 AM

Copyright 2018 Redgate Software. Privacy Policy