troubleshooting Question

Problem Sending Multiple Emails in 1 SQL 2008 Job

Avatar of tpezet
tpezet asked on
Microsoft SQL Server 2008
2 Comments1 Solution279 ViewsLast Modified:
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;

DECLARE      @TO NVARCHAR(60), @SUBJECT  NVARCHAR(256)
DECLARE @MESSAGE NVARCHAR(4000),  @FROM NVARCHAR(60)

      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.
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros