Email alert for scheduled task job

  • Hello Guys,

    I have a lot of jobs running on the schedule task. I need to know a way using which I can setup email alerts once the job completes. I am using Windows server 2003 and the job copies files to DR site. I have batch file code which would do that. Any help would be appriciated.

    Thanks A tonn in advance,

    Nikhil Parsi

  • create a step as last step (lets say : Email Status) of the job which notifys you by emailing. set the OnSucceess status of actual last step to this step.

    let me know you have questions

    thanks

    Joseph

  • thanks for the reply

    I just want to make sure if you got this as a windows scheduling task. Can you provide me the code for step i.e code in batch file as I have it in batch format.

    Thanks,

    NIkhil

  • one way i guess you could do it is write an sp that uses the send mail procedure and pass in a parameter of a job name. then in your batch file call the sp using osql and pass the parameter in as the name of the batch file.

    Im sure there are ways of sending emails from command line but im not the man to know the answers - sorry

  • You can install sendmail.exe and then use a batch file to send an email

    http://glob.com.au/sendmail/

    here is the code for the batch file

    set MailFrom=

    set MailTo=

    rem MailTo can be multiple addresses separated byt a ;

    set Subject="SQL Server Agent Job Failure"

    set Message="There was a failure of a SQL Agent Job on DB1"

    set FileName=

    rem If no attachment is desired, then use Set FileName=NONE

    set AppPath=c:\sendemail.exe

    set Relay=mailrelay.'ENTER MAILRELAY NAME'.com

    if %FileName%==NONE (

    %AppPath% -f %MailFrom% -t %MailTo% -u %Subject% -m %Message% -s %Relay%

    ) else (

    %AppPath% -f %MailFrom% -t %MailTo% -u %Subject% -m %Message% -a %FileName% -s %Relay%

    )

  • thanks a lot for the reply.

    I was wondering if the software you specified was only for UNIX as I am using windows server 2003. Also, do you know any other softwares or methods apart from this. Any ways thanks for the help.

    Nikhil

  • Hi,

    If you are attempting to send email from your local server without having SMTP installed (sendmail client) you can use CDOSYS and VBScript.

    Visit this web page, it covers a script using systems having the SMTP service installed:

    http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/tag/cdosys-object/

    Check out:

    http://windowsitpro.com/article/articleid/23744/sending-email-notifications.html

    Look at Listing B, it addresses using a remote SMTP server at http://windowsitpro.com/Files/04/23744/Listing_02.txt

    Many of the Windows-based email options include the requirement of an email "profile". These examples should not require profiles and can be called from a batch (.bat or .cmd) file using CSCRIPT or WSCRIPT.

    Let me know if you have any questions, just one from my end.

    Why isn't this all using SQL Agent for the starting and status of the jobs? Alerting is built-in, no need to create a custom solution. (This is a SQL Server 2005 forum, or am I lost?)

  • sorry i thought it is a SQL job..

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply