Quantcast
Channel: SQLServerCentral » SQL Server 2012 » SQL Server 2012 - T-SQL » Latest topics
Viewing all articles
Browse latest Browse all 4901

Database Mail Frustrations

$
0
0
We have a new server with SQL Server 2012. Database mail has been configured and appears to be working. I am seeing some strange behaviour though and I don't know if it is an issue with SQL Server, Exchange or the infrastructure. This is what I am seeing:1. Create a cursor to send myself 10 emails.[code="sql"]DECLARE @i INT = 1;WHILE @i <= 10BEGIN EXEC msdb..sp_send_dbmail @profile_name = 'my_profile', @recipients = 'me@mydomain.co.za', @subject = 'Test', @body = 'Testing Mail'; SET @i = @i + 1;END;[/code]2. Monitor the msdb mail tables[code="sql"]SELECT 'Unsent', COUNT(*)FROM msdb..sysmail_unsentitemsWHERE sent_date > '2012-11-19 14:15'UNION ALLSELECT 'Failed', COUNT(*)FROM msdb..sysmail_faileditemsWHERE sent_date > '2012-11-19 14:15'UNION ALLSELECT 'Sent', COUNT(*)FROM msdb..sysmail_sentitemsWHERE sent_date > '2012-11-19 14:15'UNION ALLSELECT 'All', COUNT(*)FROM msdb..sysmail_allitemsWHERE sent_date > '2012-11-19 14:15'[/code]For about 1 minute after I have run my code I see NOTHING in these tables.Unsent 0Failed 0Sent 0All 0Then I have 10 entries in the unsent table. They all have a sent_status of retry.Unsent 10Failed 0Sent 0All 10After a few more minutes I see they have all failed.Unsent 0Failed 10Sent 0All 10However, I have 20 emails sitting in my inbox. So somehow SQL Server sends me two copies of each email then reports them as failed.I also have 20 errors in the Database Mail Log, all of which say:The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 4 (2012-11-19T14:36:58). Exception Message: Cannot send mails to mail server. (The operation has timed out.).And I also have the following error in the SQL Server Log:An error occurred in Service Broker internal activation while trying to scan the user queue 'msdb.dbo.InternalMailQueue' for its status. Error: 1222, State: 51. Lock request time out period exceeded. This is an informational message only. No user action is required.Any ideas?

Viewing all articles
Browse latest Browse all 4901

Trending Articles