Stored procedure using SP_SEND_DBMAIL sending duplicate emails to all recipients

andewM picture andewM · Mar 20, 2013 · Viewed 34.3k times · Source

I have a stored procedure that is run every night which is supposed to send the results of a query to several recipients. However on most days it ends up sending a duplicate email a minute later. The code I am using is as follows (all emails and database refs have been changed):

EXEC msdb.dbo.sp_send_dbmail
@recipients = '[email protected]',
@copy_recipients = '[email protected];[email protected];[email protected]',
@subject = 'Example Email',
@profile_name = 'ExampleProfile',
@query = 'SELECT name
    FROM table
    WHERE date BETWEEN (getdate() - 1) AND getdate()',
@attach_query_result_as_file = 1

Any help with this would be greatly appreciated.

Answer

andewM picture andewM · Apr 26, 2013

The solution has turned out to be reducing the number of Account Retry Account on the server to 0 (within the Database Mail Configuration Wizard).