Sending Email through SQL Server FAILED

vfhzx4xs  于 5个月前  发布在  SQL Server
关注(0)|答案(3)|浏览(70)

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). )"

o4tp2gmn

o4tp2gmn1#

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
cx6n0qe3

cx6n0qe32#

If you are using GMAIL then please take care of one extra step below:

  • After you configure the email in the Database Mail, Please log in your gmail account and go to

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:

USE msdb
    GO
    EXEC sp_send_dbmail @profile_name='XXX', -- Your profile name
    @recipients='[email protected]', -- Recipient's email address
    @subject='Test message',
    @body='This is the body of the test message.'

At last, try to run following query to see whether its sent or not

SELECT * FROM sysmail_log
jfewjypa

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:

  1. Double check the server name using: SELECT servername FROM sysmail_server
  2. Try to reset the server name using: EXEC dbo.sysmail_update_account_sp @account_name = '(your account name)', @mailserver_name = '(your server name)'
  3. Try to ping the server name and see if the name resolves to an IP address (the server doesn't need to respond to the ping, you just need to see the IP address returned)
  4. Try using IP address in place of the server name to see if that solves the error (this would bypass any DNS problems you may be having)

相关问题