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). )"
3条答案
按热度按时间o4tp2gmn1#
Some suggested troubleshooting steps:
cx6n0qe32#
If you are using GMAIL then please take care of one extra step below:
https://www.google.com/settings/security/lesssecureapps
Turn on your less secure app to use your account, that's how the database mail can access your gmail SMTP account.
Try sending test mail using following code:
At last, try to run following query to see whether its sent or not
jfewjypa3#
The error "No such host is known" indicates a DNS problem where the @mailserver_name you provided to the sysmail_add_account_sp can't be resolved.
I got this error because I originally called sysmail_add_account_sp with the @mailserver_name parameter using a string that accidentally had a leading space. Resetting the server name as noted in item 2 below without the leading space fixed my issue.
Try these things: