Search code examples
sql-serversql-server-2008sp-send-dbmail

Sending Email through SQL Server FAILED


I am setting up Database mail in SQL Server 2008 to send mail to my Gmail account. Following are the details of the DBMail profile I've created:

email id : [email protected]
Display Name : xyz
Reply email :
Server name : smtp.gmail.com
port no: 587
Check : This server requires a secure connection
Check : Basic Authentication
username : [email protected] ( should have gmail.com)
password : <mypassword>
confirm password : <mypassword>

Then I clicked next and also made it default public profile.

Then I use the following TSQL code to configure and send DBMail:

EXEC sp_CONFIGURE 'show advanced', 1
GO
RECONFIGURE
GO
EXEC sp_CONFIGURE 'Database Mail XPs', 1
GO
RECONFIGURE
GO

use msdb
go
EXEC sp_send_dbmail 
@profile_name='XYZ',
@recipients='[email protected]',
@subject='Test message',
@body='Message Sent Successfully'

The output appears "Message Queued"

Still my message is getting failed. I feel I have setup the server correctly. Any input would be appreciated.

 SELECT * FROM sysmail_log

The body column shows

"The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2012-05-16T17:05:00). Exception Message: Could not connect to mail server. (No such host is known). )"


Solution

  • Some suggested troubleshooting steps:

    1. Try to send a message through the same SMTP server, using the same machine as SQL Server, using a client mail program like Outlook. You may get a more meaningful error message.

    2. The port may be blocked. Try sending mail to any other SMTP server using port 587.

    3. Try changing to port 465.

    4. Try unchecking the "requires a secure connection" bit in your profile.

    5. Try using an SMTP server inside your network to relay to GMail. This might be easier to set up and get running. You'll need to install IIS and the SMTP components if you don't have a local SMTP server available to handle the relay.

    6. Review http://mail.google.com/support/bin/answer.py?hl=en&answer=13287