question

Damus avatar image
Damus asked

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,

Damus

sql-server-2005dbmail
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

David Wimbush avatar image
David Wimbush answered

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.

3 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

+1 - sp_send_dbmail is also much more reliable, configurable and doesnt require a SMTP Client (such as Outlook) to be installed on the server.
1 Like 1 ·
'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
1 Like 1 ·
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?
0 Likes 0 ·
Brimstedt avatar image
Brimstedt answered

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.

1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.