This is about SQL Server 2005. I have configured SQL agent jobs to send an email when it failed. So far I have received email reliably.
However, I have an weird problem where an email would get queued but not delivered immediately. As an example, a job failed on April 1 at 9 AM. When I query
SELECT * FROM dbo.sysmail_mailitems
It will show the error mail has a send_request date on 2015-04-01 09:01:30.000, however, I just received the email today, and the sent_date is shown as 2015-04-02 10:10:51.000.
I checked the database mail log, and the database mail process did NOT start on 2015-4-1. It is only started on 2015-04-02 10:10:51.000, and at that time I open the Database Mail dialog box (I did not change anything - I just opened it to check a few settings).
The database mail log (sysmail_event_log)
2015-03-22 01:00:18.597 DatabaseMail process is started
2015-03-22 01:10:21.013 DatabaseMail process is shutting down
2015-04-02 10:10:50.393 DatabaseMail process is started
2015-04-02 10:20:53.960 DatabaseMail process is shutting down
The previous job error was on 3/22 and the email was sent properly. The latest error on 4/1 didn't.
The server is not under stressed, and there is no error message in the server log. It is just the Database Mail process did not start even when a mail is queued for some reason.
Summary:
Expected behaviour:
- Job failed
- Agent queue an email
- Databasemail process starts
- Email sent
- Databasemail process stops
Actual behaviour:
- Job failed
- Agent queue an email
- Databasemail process did not start immediately
- Databasemail process decided to start after 2 days for unknown reason
- Email sent, 2 days late
- Databasemail process stops
SELECT * FROM msdb.dbo.sysmail_event_log order by log_date desc
andSELECT * FROM msdb.dbo.sysmail_unsentitems
?