Chandresh Khambhayata Chandresh Khambhayata - 4 years ago 216
SQL Question

Unable to send email from SQL Server

I am trying to send an email from SQL Server to Trigger. I have performed as per the guidance in this blog. Whenever I am trying as email, I am getting an error.

EXEC msdb.dbo.sysmail_add_account_sp
@account_name = 'ChandreshTestAccount'
, @description = 'Sending email from test account'
, @email_address = 'chandresh.cmk@gmail.com'
, @display_name = 'No-Reply'
, @replyto_address = 'chandresh.cmk@gmail.com'
, @mailserver_name = 'smtp.gmail.com'
, @port = 25
, @username = 'chandresh.cmk@gmail.com'
, @password = 'xxxxxxx'
Go



Error: The mail could not be sent to the recipients because of the
mail server failure. (Sending Mail using Account 6
(2017-02-02T14:24:46). Exception Message: Could not connect to mail
server. (A connection attempt failed because the connected party did
not properly respond after a period of time, or established connection
failed because connected host has failed to respond 74.125.68.109:25).
)


Then I have tried to change the port number 587 and got the below error.


The mail could not be sent to the recipients because of the mail
server failure. (Sending Mail using Account 5 (2017-02-02T14:28:22).
Exception Message: Cannot send mails to mail server. (The SMTP server
requires a secure connection or the client was not authenticated. The
server response was: 5.7.0 Must issue a STARTTLS command first.
n8sm30283000pgc.16 - gsmtp). )


Then again I have tried to change the port number 465 and got the below error


The mail could not be sent to the recipients because of the mail
server failure. (Sending Mail using Account 4 (2017-02-02T14:28:19).
Exception Message: Cannot send mails to mail server. (Failure sending
mail.). )


Is there anything I am missing?
Note: I am trying this in Local Machine and I am able to send email from
C#
code with
Port 25


Thank You.

Answer Source

As explained in the Q&A Sending email in .NET through Gmail, on MSDN: How to configure SQL Server Database Mail to send email using your Windows Live Mail Account or your GMail Account and so on, you need to use port 587 and a secure connection, as the error you received indicates:

5.7.0 Must issue a STARTTLS command first

So, pass the @enable_ssl=1 parameter to sysmail_add_account_sp as explained in MSDN: sysmail_add_account_sp (Transact-SQL).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download