Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Problem Sending Multiple Emails in 1 SQL 2008 Job

Posted on 2009-12-16
Medium Priority
Last Modified: 2012-05-08
I am trying to send multiple emails from a single MS SQL 2008 Job.  The emails are monthly standard jobs that go into our helpdesk system.

The problem is that the first EXEC fires off the email but any subsequent ones don't.   The list of emails is all in one step of the job.  I tried surrounding the EXEC part with a BEGIN And END but it made no difference.  Any help would be appreciated.

The code I am using is as follows;


      SET @SUBJECT='(DRA) Confirm Scope of backups'
      SET @MESSAGE ='Confirm Scope of Backups'
      SET @FROM=N'dbmail@mycompany.com.au'
      SET @TO = N'helpdesk@mycompany.com.au'
            EXEC msdb.dbo.sp_send_dbmail
            @profile_name = 'Helpdesk',
            @recipients = @TO,
            @body = @MESSAGE,
            @subject = @SUBJECT

      SET @SUBJECT='(SEC) Check Swipe card Access to Server doors'
      SET @MESSAGE ='Check Swipe card Access to Server doors'
      SET @FROM=N'dbmail@mycompany.com.au'
      SET @TO = N'helpdesk@mycompany.com.au'
            EXEC msdb.dbo.sp_send_dbmail
            @profile_name = 'Helpdesk',
            @recipients = @TO,
            @body = @MESSAGE,
            @subject = @SUBJECT

The job history indicates that the job has completed successfully.
Question by:tpezet

Accepted Solution

Cyrun earned 1000 total points
ID: 26064976
When I run this code against my test system both e-mails are sent and received.

You may want to take a look at your e-mail server security/ati spam settings. It may not like the e-mails coming in from one source that fast and may think it's being spammed.

A simple way to test this theory would be to add a WAITFOR DELAY 'hh:mm:ss' between the two messages.

Hope this helps you with some ideas, good luck!

Author Comment

ID: 26068674

Thanks for the response.  The delay did change the behaviour such that all emails came through so it does point to our exchange server.  

I then looked at the mail server and when I disable our Trend Micro Scan mail anti-spam rule they come through without the WAIT FOR DELAY code.   So you are correct.

Much appreciated for your help

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question