Setting Database Mail on SQL Server 2005/2008

I was creating a web service that processes data and saves into relevant tables. Should there be any error in the process, an error record was created. Although there are many ways to be alerted when an error occurred, I felt that in this case it was more appropriate to use a Stored Procedure to send an error email.

In SQL Server 2005/2008, the Database Mail feature need to be setup. The Database Mail feature allows SQL Server to send emails to end users. The only pre-requisite is to have an SMTP server available.

Right click on Database Mail and check Configure Database Mail...

Create a new profile called testProfile

Create testAccount SMTP account that will be associated with the testProfile

testAccount created

Public Profiles

Configure System Parameters

Configure System Parameters

Summary

Summary

Confirmation

Confirmation

Database Mail is now configured and ready for use. Let’s send a test mail to confirm that it is configured properly.

Send test email

Send test email

Send test email

Send test email

Email Sent

Check your inbox...

Now that we have Database Mail working, we can use the following syntax to send email:

EXEC [msdb]..[sp_send_dbmail]
@profile_name = 'testProfile',
@recipients = 'To@email.com',
@subject = 'Error Message',
@body = 'Include error message',
@body_format = 'HTML'

Leave a Reply

Spam Protection by WP-SpamFree

RedGate SQL-Compare
RedGate SQL-Compare
RedGate Data Compare
RedGate Data Compare
Quest Spotlight
Quest Spotlight
Quest Performance Analysis
Quest Performance Analysis