Thursday, November 20, 2008

Send mail using smtp.gmail.com from Database mail (DBMail) in SQL Server 2005 2008

Just started research on how to send mail through gmail smtp service from database mail in SQL Server 2005 and 2008 after seeing a request from one of the user in forum.

There are two methods available (Click on name to get details else scroll down)
1. Use SSL Wrapper.
2. Directly configure DBMail to connect to smtp.gmail.com

Method 1:
Step 1: Install stunnel http://www.stunnel.org/
Add below settings to stunnel.conf after installation

service=gmailSmtp
[gmailSmtp]
accept = 127.0.0.1:111
connect = smtp.gmail.com:465 (If 465 is not working then try 587)

2. Change Database mail smtp server to 127.0.0.1 port: 111 (do not check SSL)

Method 2:
In database mail when you create an account, use these values.

Account name: SQL Alerts System
Description: Alerts from SQL Server

Outgoing mail Server (SMTP)

Email id: yourname@gmail.com
Display Name: SQL Alerts
Reply email: yourname@gmail.com
Server name: smtp.gmail.com
Port no: 587 (If this does not work then try 465)
Check : This server requires a secure connection
Check Basic Authentication
username: yourname@gmail.com
password: yourpassword
confirm password: yourpassword
click next and also you need to make it default public profile.

After you do this, you also have to do below change in SQL Server Agent properties
In Properties click alerts system and then select database mail.
Now restart only SQL SERVER AGENT and test your database mail.

Check Status:
Right click database mail, select view database mail logs keep refreshing to see if any error message had occured. mean while look in your inbox if you recieved your email.
Still if you are not receiving email then firewall could be blocking the communication so test it using telnet command as below
1. Go to Start --> Run --> Type "cmd" or "command.com"
2. Now once command prompt is opened then type "telnet smtp.gmail.com 587" without double quotes in the promt and you should get greeting message as "220 mx.google.com ESMTP...." then there is no firewall block so type "quit" and close session. If you are not getting above message then there is some firewall block issue which will show message like "Connecting To smtp.google.com...Could not open connection to the host, on port 587: Connect failed"

No comments:

Post a Comment

Please do not spam!