Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

martin

Re: Need help with sending email notification after successful /failed uploads in batch script

A full example, including the PowerShell script to send the email:
https://winscp.net/eng/docs/script_email
Guest

disregard. its solved
bumz

Need help with sending email notification after successful /failed uploads in batch script

Hi
I am new to writing batch files. I am looking to set up email notification if it failed or success for a upload. list below is my batch file.
@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\FTPLogs\VCAL.log" /ini=nul ^
  /command ^
    "open sftp://******:******/ -hostkey=""*********""" ^
    "synchronize remote E:\VCAL /Diagnostics_******/VCAL" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
) else (
  echo Error
)
 
exit/b %WINSCP_RESULT%

The batch file works I just don't know how to setup the email. Please help! I have an IIS server that I can use as an smtp server to send emails. I just don't know how to add the code in the script above. When the upload exit code = 0 send success email. When exit code = 1 send fail email. I Have a batch file and my code inside is to call powershell run a ps1 script to send an email:
Powershell.exe -executionpolicy remotesigned -File  C:\bin\test\email.ps1

How do I make it work with the code above? thanks in advance.