SQL Server Database Mail was introduced with SQL Server 2005 onwards and provides a very good way of sending E-Mails through SQL Server. This is very good feature and used widely. It is easy to configure database mail once we know the SMTP server name which can be used to send our E_Mails. Most often or not there are no problems configuring or using database mail feature, however there can be cases where there are problems sending E-Mails.
We would like to discuss about one of the weird issue which causes the database mail to fail sending E-Mails to some E-Mail addresses. In this scenario, Database Mails can be sent to all E-Mail addresses which are part of same network or domain in which the Mail server or SMTP server belongs, but mails cannot be sent to outside networks.
Example: SMTP server name is in domain MyDomain.com and E-Mails can be sent to any E_Mails which belong to this same domain DBA@MyDomain.com, but it fails when we try to send to some other domain like firstname.lastname@example.org, etc. Below is the error message received.
The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 4 (2014-08-23T25:22:48). Exception Message: Cannot send mails to mail server. (The operation has timed out.).
This issue happens due to various reasons. First make sure that the mails can be sent to these addresses from this SMTP server. You can test this by sending the E-Mail from outlook to the failed E-Mail address. Sometimes some domains may be blocked.
If it fails to send E-Mail to local domain, then check if that IP address is On the Mail Server Relay and, if not then add the IP address of that domain to allow the communication. You can add the IP address from below, however this is the task of Network Administrator or Exchange Server Admin.
Mail server -> Exchange Server Manager -> SMTP Connector Properties -> Access Properties -> Access Tab -> Relay button
Once they fix this issue, then the E-Mails can be sent through SQL Server without any problems.
What is SQL Server Database Mail?
Database Mail is an enterprise solution for sending e-mail messages from the SQL Server Database Engine. Using Database Mail, your database applications can send e-mail messages to users. The messages can contain query results, and can also include files from any resource on your network. Database Mail is designed for reliability, scalability, security, and supportability.
This is applicable on below versions of SQL Server
SQL Server 2005
SQL Server 2008 R2
SQL Server 2012
SQL Server 2014
Hope this was helpful.
In-Depth Blogs on SQL Server, Information about SQL Server Conferences and Events, SQL Server Frequently asked questions, SQL Server Trainings.