Help with sending email result on failed transfer

Advertisement

Robpwl
Guest

Help with sending email result on failed transfer

Hello

I'm trying to get my transfers to send out an email after a failed transfer, but can't get it to work. I'm using Sendmail and the example script part pasted over WinSCP auto-generated batch file code but to no avail. Couldn't find anything from google nor this forum, so please check and tell me what I'm missing here
@echo off
 
"C:\Program Files (x86)\WinSCP\WinSCP.com" ^
  /log="C:\WinSCP logid\WinSCP.log" /ini=nul ^
  /command ^
    "open sftp: Server =""" ^
    "lcd Folder location" ^
    "cd User" ^
    "put *.csv" ^
    "exit"
 
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
  C:\Program Files (x86)\WinSCP\sendmail.exe -t < C:\Program Files (x86)\WinSCP\success_mail.txt
  exit /b 0
) else (
  echo Error!
  C:\Program Files (x86)\WinSCP\sendmail.exe -t < C:\Program Files (x86)\WinSCP\error_mail.txt
  exit /b 1
)
 
exit /b %WINSCP_RESULT%
All the necessary files are in the WinSCP folder, success_mail contains the same as example, just To and From replaced with my own (I think that's a need?) and sendmail.ini modified to have my SMTP server and the account for it. Also enabled debugging and error logging but they aren't logging anything, so it feels like it isn't even doing anything past the transfer

WinSCP log itself contains in the last lines:
Script: exit
Script: Exit code: 0
Sending Special code: 1
Thanks in advance!
Robert

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
36,510
Location:
Prague, Czechia

Re: Help with sending email result on failed transfer

Well, this does not seem to be a WinSCP question.
But one obvious problem is that you are missing double quotes around the paths with spaces:
"C:\Program Files (x86)\WinSCP\sendmail.exe" -t < "C:\Program Files (x86)\WinSCP\success_mail.txt"
Adding 3rd party files to WinSCP installation folder does not seem a good idea either, but that's your call.

Reply with quote

Robp
Joined:
Posts:
3

Re: Help with sending email result on failed transfer

I've tried with both quotes and without, neither work. It was just sendmail.exe < .... before but thought that maybe adding the absolute path would help. Made a new folder for it, which did absolutely 0.
I placed sendmail into the winscp folder as per this tutorial https://winscp.net/eng/docs/script_email

Can I maybe make a different bat file that would run after the transfer, that would then call the sendmail and logging part? It still feels like the bat file isn't calling or even doing the log check part

Best regards
Robert

Reply with quote

Robp

The batch file returns/echos Success at the end. Did some compatibility tricks (mark run as admin and run this program win xp sp3) and got the batch file to actually start sendmail.exe but it stops/freezes and debug says message begins. Haven't found a single topic on google about this, everything related to this is in php

Reply with quote

Advertisement

Robp
Joined:
Posts:
3

Okay figured it out or rather did a work around
Sendmail part in the WinSCP result looks like this
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
  echo Success
  call "C:\sendmail\success.bat"
) else (
  echo Error!
  call "C:\sendmail\failure.bat"
)
exit /b %WINSCP_RESULT%
Success.bat looks like this
C:\sendmail\sendmail.exe -F WinSCP -f SENDER@DOMAIN.ABC RECEIVER@DOMAIN.ABC < C:\sendmail\success_mail.mail
exit /b 0
Sendmail.ini contains – SMTP server, both logfiles, authentication and smtp_ssl set to none. Rest are commented out

Sendmail.exe has a "Set for all users" run as admin and run as Win XP SP3 and the WinSCP transfer bat file is run as admin

I tested with both the success.bat in the transfer script and in the .bat, but found that it would only work when I called it as another .bat file
Hope this helps someone like me

Best regards
Robert

Reply with quote

martin
Site Admin
martin avatar

Ok, good that you made it working. Though I cannot imagine how moving the command to another batch file can make any difference.

Reply with quote

Advertisement

You can post new topics in this forum