4

I have Sql Server Agent Jobs which send emails once a day, each of them containing one excel file. They are similar to each other in many ways; they complete the steps successfully, and have no problem with sp_send_dbmail procedure.

    USE msdb
    GO
    DECLARE  @tablename varchar(200)
    set @tablename = 'MyTable' + '.xls'
    EXEC sp_send_dbmail 
    @profile_name = 'x',
    @recipients = 'example@abc.com',
    @copy_recipients = ' example2@abc.com',
    @subject = 'Excel Report',
    @body =  'File attached.',
    @file_attachments =  @tablename

However; some of these jobs send the email twice. I have checked that the jobs run once a day and sp_send_dbmail procedures are called once. I disabled&enabled the job, still getting double mails. I deleted and re-created the job, it made no difference. It is really interesting how other similar jobs just work very fine, while another one just sends the mail two times.

Any ideas about what the reason can be for the Job to send duplicate emails?

betty.88
  • 157
  • 5
  • well kind of hard for someone to offer any viable answer without seen the code that is Invoked or the Stored Procedure .. perhaps posting some code will help. also have you thought that perhaps 2 Instances of the Job are running..? – MethodMan Aug 01 '13 at 07:36
  • After a long search I've found out that it was about the mail groups the job was sending the mails to. Generally there was no problem with neither the job nor the mail groups, but I removed the mail group and wrote the people's mail addresses one-by-one and the problem got solved... Still am not sure why it didn't send it properly; perhaps because the mail group included another mail group..? – betty.88 Aug 14 '13 at 12:31
  • I want to update the information that if a recipients e-mail address is no more in use, this could be another reason for the job to be sent twice. Finally things are more clear. – betty.88 Sep 05 '13 at 08:31

2 Answers2

2

necro bump.

we had this issue, and it was also caused by an email address in the recipient list.

if we had something of the form - 12a34b45c.abcd.com@amer.teams.ms

included, then a second email would get sent 1 minute later.

user2983931
  • 304
  • 5
  • 17
0

Send a test mail from outlook to all recipients and CC.
Your SMTP relay would inform you those invalid email addresses like enter image description here or enter image description here After identified the invalid emails, you can remove/replace them so the rest of recipients will no longer get the duplicate ones.

You may also consider closing SQL Server email retry

EXECUTE msdb.dbo.sysmail_configure_sp 'AccountRetryAttempts', '0' ;

But having the invalid emails cleaned would be a better practice.

Circle Hsiao
  • 1,497
  • 4
  • 22
  • 37