Background:There is a SQL Agent job that's been running for years (original developer is gone), which sends about 300+ emails a day, and there's a 4-second delay between sends. I've been asked to figure out if I can remove the timer, since this program takes at least 20 minutes a day, and there are items after this which can't run until all of the emails go out.It looks like if I remove the timer, or decrease it anywhere beneath 4 seconds, that we'll send duplicate emails (the quicker I send them, the more duplicates I see). I was reading that when SQL Server thinks that the SMTP server is unavailable, the email is marked as failed, and if Account Retry Attempts is > 0 then the email will be re-tried (after the number of seconds depicted in Account Retry Delay). It looks like that's certainly what's happening here, because I see the duplicate emails marked as failed in the sysmail_faileditems table/view. Following a suggestion I found online, if I set Account Retry Attempts to 0, I send the exact number of emails I'm expecting. In this case I still see failed emails sitting in sysmail_faileditems (despite their successful delivery).So, in actuality these aren't failing. And I'd prefer that emails be re-tried in the case that the SMTP server isn't available. For now I'm going to follow my cautious side and leave the Account Retry Attempts at a value >0 and leave the 4-second timer in there. But is there something else that I can tweak (or ask our Exchange admin to tweak) so that emails that are actually sent aren't marked as failed, or that the SMTP server can process requests faster?I'm just using the following code in order to send 100 emails to myself:[code]declare @l_cnt int, @l_subject varchar(100), @l_minute varchar(5);set @l_cnt = 1;set @l_minute = convert(varchar(2),datepart(mi, getdate())) + ':' + convert(varchar(2),datepart(s, getdate()));while @l_cnt <= 100 begin set @l_subject = 'Email #'+ right('00'+convert(varchar(4), @l_cnt),3)+' group-'+@l_minute; EXEC msdb.dbo.sp_send_dbmai @profile_name = 'Mail_Profile', @recipients = 'my.email@addr.com', @body = 'nada', @subject = @l_subject; --waitfor delay '00:00:02'; set @l_cnt = @l_cnt+1; end;[/code]Thanks,--=Chuck
↧