Please enable Javascript to correctly display the contents on Dot Net Tricks!

SQL Server Database Mail Setup

  Author : Shailendra Chauhan
Updated On : 24 Sep 2016
Total Views : 116,880   
Support : SQL Server 2005,2008
 

Recently, I have configured database mail in SQL Server 2008. Here, I am sharing what I have learnt and how did I configure this powerful feature of sending mail in SQL server 2008.

Database mail feature was introduced in SQL server 2005 by Microsoft. This feature is also available in SQL Server 2008 and 2012. Before Database mail we have SQL Mail feature in Sql Server 2000.

Database Mail is more reliable, secure, faster than SQL Mail in SQL Server 2000. SQL Mail is based on MAPI (Messaging Application Programming Interface) where as Database Mail is based on SMTP (Simple Mail Transfer Protocol. Moreover database mail uses service broker service and this service need to be enabled for Database Mail.

By default, SQL Database mail is not enabled. We can enable this feature by using system defined stored procedure, configuration manager or by Database Mail Wizard. I am sharing both the tricks to enable this feature.

Setup SQL Database Mail

We can configure SQL Database mail in following steps by using Database mail wizard as show below.

  1. Create Profile and Account

    In first step we will create a profile and account by using the Configure Database Mail Wizard as shown below.

    A profile can have multiple email accounts. It can be of two types.

    1. Public Profile

      A public profile can be accessed by any users and these users will have the ability to send emails.

    2. Private Profile

      A private profile only accessed by granted users and only these users have the ability to send emails.

  2. Configure Database Mail

    After successfully creation of Profile and Account, we will configure the Database Mail using system defined stored procedure “sp_configure ” as shown below.

     GO 
    sp_CONFIGURE Database Mail XPs', 1 
    GO 
    RECONFIGURE 
  3. Send Test Mail

    We can send test mail by using wizard and T-SQL statement as shown below.

    Using Wizard

    Using T-SQL Statement

     USE msdb 
    GO 
    EXEC sp_send_dbmail @profile_name='Shailendra Chauhan Profile', @recipients='shailendra@ymail.com', @subject='Database Mail Test', @body= ‘This is a test e-mail sent from Database Mail' 
  4. Check Your Inbox

    After sending test mail, you need to check the mail received in your inbox. I received the mail "Database Mail Test" in my inbox as shown below:

Summary

In this article I try to explain how to setup SQL Database Mail in Sql Server with example. I hope after reading this article you will be know how to configure SQL Database Mail in Sql Server. I would like to have feedback from my blog readers. Please post your feedback, question, or comments about this article.

YOU MIGHT LIKE
Free Interview Books
 
COMMENTS (0)
14 DEC
ASP.NET MVC with AngularJS Development (online)

MON-FRI 07:30 AM- 09:00 AM IST

Know More
5 DEC
AngularJS Development (online)

Mon - Fri     6:30 AM-7:30 AM IST

3 DEC
AngularJS Development (offline)

SAT,SUN     11:00 AM-12:30 PM IST

3 DEC
MEAN Stack Development (offline)

Sat, Sun     (09:30 AM-11:00 AM IST)

26 NOV
ASP.NET MVC with AngularJS Development (offline)

(SAT,SUN)     03:30 PM-05:00 PM IST

24 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     09:30 PM-11:00 PM IST

12 NOV
ASP.NET MVC with AngularJS Development (offline)

SAT,SUN     08:00 AM-09:30 AM

3 NOV
ASP.NET MVC with AngularJS Development (online)

MON-FRI     07:30 AM-09:00 AM IST

25 OCT
.NET Development (offline)

Mon-Fri     9:00 AM-11:00 AM IST

BROWSE BY CATEGORY
 
RECENT ARTICLES
SUBSCRIBE TO LATEST NEWS
 
LIKE US ON FACEBOOK
 

Professional Speaks

+