env: Windows Server 2016
SQL Server 2016 SP2
It was found a few days of how SQL Server did not send some warning of mail, it is management's too good? Feel less likely because machines have few resources, there will be some warning of stress tests.
So start step by step to check SQL Server database mail
1. Check database mail queue status and
command:
EXEC msdb.dbo.sysmail_help_queue_sp
database mail queue even have 383, do not send out a lot of mail
2. Check whether to activate the database mail
command:
EXEC msdb.dbo.sysmail_help_status_sp
database mail determined to start
3. Use a query command again to confirm whether the mail has not been sent, and which mail has been sent
command:
SELECT * FROM msdb.dbo.sysmail_sentitems;
SELECT * FROM msdb.dbo.sysmail_unsentitems;
The mail has been sent is 0, but there are a lot of unsent mail record of
4. Verify that the service broker msdb is enabled
command:
SELECT is_broker_enabled FROM sys.databases WHERE name = 'msdb';
has enabled the service broker msdb
5. Because could not find where the error, the Microsoft official looking documents ever look
Results found the following message
SQL Server 2016 SP2 CU4
https://support.microsoft.com/en-gb/help/4464106/cumulative-update-4-for-sql-server-2016-sp2
When you install Cumulative Update 1(CU1), CU2 or CU3 for Microsoft SQL Server 2016 Service Pack 2, you will notice that the config file DatabaseMail.exe.config may be removed. Additionally, the Database Mail feature may not work correctly and cannot send email messages.
Which referred to DatabaseMail.exe.config This file may be removed.
After the examination, can confirm that will be removed.
SQL Server 2016 SP2 CU5
https://support.microsoft.com/en-us/help/4475776/cumulative-update-5-for-sql-server-2016-sp2
There are also bug fixes in the database mail
Another paper
SQL Server 2016 SP1 CU1
FIX: SQL Server 2016 Database Mail does not work on a computer that does not have the .NET Framework 3.5 installed or stops working after applying SQL Server update
SQL Server 2016 SP1 CU2
https://support.microsoft.com/en-au/help/4013106/cumulative-update-2-for-sql-server-2016-sp1
6. Confirm the repair mode and range
Database mail bug damage range of versions:
SQL Server 2016 SP1 CU1
SQL Server 2016 SP2 CU1, CU2, CU3
The current version of SQL Server 2016 SP2 CU1, you can use the service pack fixes, but to reboot.
7. Find can fix it without rebooting way
With service pack does not work the way
The find this a look
SQL Server 2016 SP1 CU1
FIX: SQL Server 2016 Database Mail does not work on a computer that does not have the .NET Framework 3.5 installed or stops working after applying SQL Server update
There are mentioned practices:
To work around this issue, you can implement any one of the following:
1. Create the DatabaseMail.exe.config and drop it next to the DatabaseMail.exe under the Binn folder. You can use notepad.exe or any other editor to edit it. Just make sure you save it by using UTF-8 encoding (in notepad.exe, select Save As... and in the Encoding combo box, select UTF-8):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
2. Run a repair setup action of SQL Server 2016.
3. Manually install .Net Framework 3.5 on the machine.
But I can not figure out why the .Net Framework 3.5 related ???
8. Start to repair, to confirm the existence of DatabaseMail.exe.config
Archive directory:
” C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Binn”
9. The repair database mail
Because I find this file written a bit exaggerated
In addition to establishing DatabaseMail.exe.config outside
Also perform the following steps
Run a repair setup action of SQL Server 2016.
Manually install .Net Framework 3.5 on the machine.
So I decided to ignore two steps back.
Establish DatabaseMail.exe.config action, I also find a SQL Sserver 2016 Ba files copied
Then execute the following instructions:
USE msdb;
EXEC sysmail_stop_sp;
EXEC sysmail_start_sp;
Yes, restart the database mail
10. Confirm state after the restart database mail
Once restarted, database mail will start sending mail.
So consider whether to restart money can be put unsent mail deleted
Delete unsent mail instructions:
EXECUTE msdb.dbo.sysmail_delete_mailitems_sp
@sent_status = 'unsent' ;
GO
11. mail with instructions further confirm whether the card in the queue
command:
SELECT * FROM msdb.dbo.sysmail_sentitems;
SELECT * FROM msdb.dbo.sysmail_unsentitems;
Verify that no unsent mail
There are also manually send a test mail is received.
SQL Server database mail repair done.