Wednesday, February 24, 2010

Configure Database mail and test it

This service introduced with Sql Server 2005 to send email messages. so you can get benefits from this services to send query result or report to user as text or attachment by using SMTP protocol.


Note:
SQLMail exists to current version for backward compatibility. You should not use SQLMail in new development because support will be removed in a future version of SQL Server.
SQLMail is based on MAPI (Messaging Application Programming Interface) and Database mail depends on Service Broker. Database Mail can be encrypted for additional security. Additionally, for MAPI to be enabled for SQLMail it will require Outlook to be installed.

Now follows these Steps to configure database mail:
  1.  Open SSMS and connect to your instance name
  2. Expand Management folder and right click on "Database mail" and choose configure database mail
  3. On welcome page wizard click next
  4. Choose "Setup database mail …" and click next
  5. Enter Profile name and description to your first account and click on "Add"
  6. Enter your SMTP account. And then click ok and then next



  •  Configure the appropriate public or private profiles, and then click Next

  •  Configure the parameters then click next then finish.

Now to send email for testing, there are two ways:
1. By using sp_send_dbmail
2. By right click on the Database mail and choose send Test E-mail…

So let's see the first option:

EXEC msdb.dbo.sp_send_dbmail
        @profile_name = 'LocalMail',
        @recipients = 'almanhaj1@gmail.com'
        ,@body = 'Hi fadi'
        ,@subject = 'Test Email' ;


Note:

When you go through the steps of the above wizard ,it will ask you to enable database mail service because by default the service is disabled.

No comments: