Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Script to send an email based on contents of a job step's output file Expand / Collapse
Author
Message
Posted Tuesday, September 30, 2008 3:13 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, February 4, 2014 9:35 AM
Points: 1,277, Visits: 1,612
Comments posted to this topic are about the item Script to send an email based on contents of a job step's output file


Post #578706
Posted Thursday, May 9, 2013 10:48 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: 2 days ago @ 12:21 PM
Points: 150, Visits: 652
Excellent. I am adding this to my library. We had many problems with SQL Server based email because of the overhead, admittedly very small for one email. The problem is that our advertising email was also SQL based and what we needed to do was use a defined email server. So, using MSDN I created this script for SQL 2000 and updated later for later for 2005.
CREATE PROCEDURE usr_sp_send_cdosysmail
@From_Addr VARCHAR(500) ,
@To_Addr VARCHAR(500) ,
@Subject VARCHAR(500) ,
@Body VARCHAR(8000) ,
@SMTPserver VARCHAR(25) = 'localhost',
@BodyType VARCHAR(10) = 'textbody'
AS

DECLARE @imsg INT
DECLARE @hr INT
DECLARE @source VARCHAR(255)
DECLARE @description VARCHAR(500)

EXEC @hr = sp_oacreate 'cdo.message', @imsg out
EXEC @hr = sp_oasetproperty @imsg, 'configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").value','2'
EXEC @hr = sp_oasetproperty @imsg, 'configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").value', @SMTPserver
EXEC @hr = sp_oamethod @imsg, 'configuration.fields.UPDATE', NULL

EXEC @hr = sp_oasetproperty @imsg, 'to', @To_Addr
EXEC @hr = sp_oasetproperty @imsg, 'from', @From_Addr
EXEC @hr = sp_oasetproperty @imsg, 'subject', @Subject

-- If you are using html e-mail, use 'htmlbody' instead of 'textbody'.
EXEC @hr = sp_oasetproperty @imsg, @BodyType, @Body
EXEC @hr = sp_oamethod @imsg, 'send', NULL

EXEC @hr = sp_oadestroy @imsg

Post #1451265
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse