RSS Feed

Handy Script: Testing Database Mail Configurations


April 16, 2015 by Mike Hillwig

In my environment, we enable database mail on every instance. While we have very few clients or applications that use it, we use it to have our servers call for help when something goes wrong. That means it’s really important that database mail be configured properly. One of the things we have on our peer review checklist is to test database mail. One day, while working with a member of my team, I saw how cumbersome it was to click through the GUI to send a test email. This little script was quickly born:

[SQL]declare @body nvarchar(1000)
declare @subject nvarchar(1000)

select @body = ‘This is a mail test from ‘+@@servername
select @subject = ‘Mail test from ‘+@@servername

EXEC msdb.dbo.sp_send_dbmail
@profile_name = ‘dbmail’,
If you see something that shows your message was queued, it’s a good indication that SQL Server was able to send the mail message.



The next step is to validate that the message was received. I can’t tell you how many times I’ve sent messages that just never made it through.



  1. A formidable share, I simply given this onto a colleague who was doing a bit evaluation on this. And he in fact bought me breakfast because I discovered it for him.. smile. So let me reword that: Thnx for the deal with! However yeah Thnkx for spending the time to debate this, I feel strongly about it and love reading extra on this topic. If doable, as you turn out to be expertise, would you thoughts updating your weblog with more particulars? It’s extremely useful for me. Massive thumb up for this weblog post!

  2. erjilopterin says:

    I rattling happy to find this web site on bing, just what I was looking for : D as well bookmarked.

Leave a Reply

Your email address will not be published. Required fields are marked *