Troubleshooting Database Mail issues in SQL Server
Use the Database Mail Configuration Wizard, change the Logging Level to Verbose and send a test mail to investigate the point of failure.
Right click database mail –View database mail log to see error or we can SELECT * FROM msdb.dbo.sysmail_event_log ;
Check the sent_Status column in the sysmail_allitems table. The four values are sent, unsent, retrying and failed.
If the status is sent and the recipients hasn’t received the email yet, that the Database Mail external program successfully delivered the e-mail message to the SMTP server but it failed to deliver the message to the final recipient. At this point, the SMTP needs to be troubleshooted (perhaps engaged your Exchange or Mail server team)
If the status is unsent or retrying, it means that the Database Mail has not yet processed the e-mail message or is in the process of retrying after a failed attempt. This could be due to network conditions, volume of messages, SMTP server issues, etc. If the problem persists, use another profile or another mail host database.
If the status is failed, it means that the Database Mail was unable to deliver the message to the SMTP server. Check the sysmail_log table and the destination address. Also be sure that there are no Network or SMTP issues.
Send a test email outside SQL Server using below script or Other mail clients and check if the recipients are receiving mails. If they do not receive problem is outside SQL Server. Engage Exchange or other mail server teams to identify why we are not able to send emails from below script or Office outlook or Other mail clients.
Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "Hello" objMessage.From = """SENDER NAME""<e-mail ID>" objMessage.To = "To email@example.com" objMessage.HTMLBody = "<h1><font face=arial>Hello,<br>How are you?." objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtphost.dns.Mailserver.com" objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 2 objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False objMessage.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 objMessage.Configuration.Fields.Update objMessage.Send
If the mail has successfully reached to recipients from above script problem is with in SQL Server mail configuration.
Verify the following
1.Verify if Service Broker is enabled (select is_broker_enabled from sys.databases where name=‘MSDB’ (0 – disabled, 1- enabled).
To enable service broker on your database run the following query: ALTER DATABASE MSDB SET ENABLE_BROKER
Note: You will be required to have exclusive access to the database while running this statement. If you do not you will get the following error message:
Msg 5061, Level 16, State 1, Line 1. ALTER DATABASE failed because a lock could not be placed on database MSDB. Try again later.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
You will have to stop SQL Server agent to enable broker on MSDB
2.Check if Database mail stored procedures are enabled (Surface Area Configuration >> “Surface Area Configuration for Features” >> Under MSSQLSERVER, expand Database Engine, and then click Database Mail. >> Ensure that Enable Database Mail stored procedures is selected, and then click Apply).
3.Check if the user is part of DatabaseMailUserRole.
4.Check what parameters and values are used in configuration by running
A list of default values are given in BOL, topic: “sysmail_help_configure_sp (Transact-SQL)”. To modify a parameter or value you can use the following stored procedure
exec msdb..sysmail_configure_sp ‘parameter_name’, ‘parameter_value’
Check if ReadFromConfigurationFile is enabled if yes check if the DatabaseMail90.exe.config file (The default path is < drive >\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn) and has proper parameters.
5.Verify that the Database Mail executable is located in the correct directory – e.g. C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn
6.Verify that the service account for SQL Server has permission to run the executable, DatabaseMail90.exe, which requires network access to the SMTP servers specified in Database Mail accounts. Therefore, the service account for SQL Server must have permission to access the network, and the SMTP servers must allow connections from the computer that runs SQL Server.
If you liked this post, do like us on Facebook at https://www.facebook.com/mssqlwiki and join our Facebook group https://www.facebook.com/mssqlwiki#!/groups/454762937884205/