Problem Sending Multiple Emails in 1 SQL 2008 Job

Posted on 2009-12-16
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''
      SET @TO = N''
            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''
      SET @TO = N''
            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
    LVL 1

    Accepted Solution

    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


    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
    How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now