Batch Script email on success or failure

Posted on 2009-05-21
Medium Priority
Last Modified: 2013-11-30
I'm stuck trying to get the script below to send the email on success or failure. It works otherwise. When the script runs it throws the following error for the send mail portion only. Any help with this would be appreciated.

0 1242930762 2 0 0 4556 4972 0 backupserver.domain.net smtpmail 2 %s 1 0 48 protocol failure; got 501 5.5.4 Invalid Address

rem @echo off

REM This script should be run on the Networker server.


set MAILSERVER=server.domain.net
set RECIEPENTS=user@domain.com
set SERVER=backupserver.domain.net
set DESTPOOL="Backup Clone"
set DAILY1="Daily Backup Clone"
set LOG=daily_clone.log

echo Cloning started at %DATE% %TIME% >> %LOG%

nsrclone -b %DESTPOOL% -s %SERVER% -y month -w month -S -g %DAILY1% -e now -C 1 >> %LOG% 2>&1
    echo ERROR: Cloning of %DAILY1% terminated with errors %DATE% %TIME% >> %LOG%
    smtpmail -h %MAILSERVER% -s "ERROR: Cloning of %DAILY1% terminated with errors" -f Networker %RECIEPENTS% < %LOG%
) else (
   smtpmail -h %MAILSERVER% -s "Cloning of %DAILY1% Completed Succesfully" -f "Networker" %RECIEPENTS%

    del %LOG%.09
    move %LOG%.08 %LOG%.09
    move %LOG%.07 %LOG%.08
    move %LOG%.06 %LOG%.07
    move %LOG%.05 %LOG%.06
    move %LOG%.04 %LOG%.05
    move %LOG%.03 %LOG%.04
    move %LOG%.02 %LOG%.03
    move %LOG%.01 %LOG%.02
    move %LOG%.00 %LOG%.01
    move %LOG% %LOG%.00
Question by:scobb13
  • 4
  • 2
LVL 97

Expert Comment

by:Lee W, MVP
ID: 24444619
It would seem that your feeding it an invalid recipient.  Have you run the mail command outside the script?  Or considered using BLAT instead (I'm not familiar with SMTPMAIL.

Author Comment

ID: 24444639
Yes. It works if it is run outside the script.
LVL 97

Expert Comment

by:Lee W, MVP
ID: 24444691
And since you've commented out echo off, what does the line display when it runs in the script?  Copy and paste it to another window and run it from there.
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!


Author Comment

ID: 24444767
Does the same thing. I think it may have something to do with the " around the "DAILY1" variable.
LVL 10

Expert Comment

ID: 24444862
you put quotes around "networker" in the second smtpmail (success) call, but not the first (failure) call?

Author Comment

ID: 24444947
Quotes around networker didn't change anything. I'm pretty sure it's the quotes pulling to the variables into the mail subject.

Accepted Solution

scobb13 earned 0 total points
ID: 24445460
was the quotes from the set command.

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

If there is anything erroneous with Exchange Database, it causes a significant effect on email communication till the user remounts the database. Further, database crash directly affects Outlook users due to which they are unable to access their ema…
In an Exchange Crossforest migration, the distribution groups can be a very complex operation that would cause loss of time, lots of issues and continued headaches if not solved in a timely manner. I had to do a similar project so I created a sc…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

624 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