Differences
This shows you the differences between the selected revisions of the page.
| script_email 2021-03-31 | script_email 2023-05-22 (current) | ||
| Line 10: | Line 10: | ||
| ===== PowerShell Send-MailMessage ===== | ===== PowerShell Send-MailMessage ===== | ||
| - | The following batch file launches PowerShell to use its [[https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage|''Send-MailMessage'' cmdlet]]. With ''Send-MailMessage'', it is easy to send WinSCP log file as an attachment. | + | The following batch file launches PowerShell to use its [[https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage|''Send-MailMessage'' cmdlet]]. With ''Send-MailMessage'', it is easy to send WinSCP log file as an attachment. |
| <code batch> | <code batch> | ||
| Line 22: | Line 22: | ||
| rem Check WinSCP result and prepare the email message | rem Check WinSCP result and prepare the email message | ||
| if %ERRORLEVEL% equ 0 ( | if %ERRORLEVEL% equ 0 ( | ||
| - | ··set WINSCP_SUBJECT=Success | + | ····set WINSCP_SUBJECT=Success |
| - | ·set WINSCP_MESSAGE=The files were uploaded successfully. | + | ···set WINSCP_MESSAGE=The files were uploaded successfully. |
| - | ·set WINSCP_CODE=0 | + | ···set WINSCP_CODE=0 |
| ) else ( | ) else ( | ||
| - | ··set WINSCP_SUBJECT=Error | + | ····set WINSCP_SUBJECT=Error |
| - | ·set WINSCP_MESSAGE=Error uploading files, see attached log. | + | ···set WINSCP_MESSAGE=Error uploading files, see attached log. |
| - | ·set WINSCP_CODE=1 | + | ···set WINSCP_CODE=1 |
| ) | ) | ||
| Line 44: | Line 44: | ||
| if exist "%WINSCP_LOG%" set ATTACHMENT=-Attachments '%WINSCP_LOG%' | if exist "%WINSCP_LOG%" set ATTACHMENT=-Attachments '%WINSCP_LOG%' | ||
| - | powershell -ExecutionPolicy Bypass Send-MailMessage ^ | + | powershell -ExecutionPolicy Bypass -Command Send-MailMessage ^ |
| -From %SMTP_FROM% -To %SMTP_TO% -Subject '%WINSCP_SUBJECT%' -Body '%WINSCP_MESSAGE%' ^ | -From %SMTP_FROM% -To %SMTP_TO% -Subject '%WINSCP_SUBJECT%' -Body '%WINSCP_MESSAGE%' ^ | ||
| %ATTACHMENT% -SmtpServer %SMTP_SERVER% -UseSsl ^ | %ATTACHMENT% -SmtpServer %SMTP_SERVER% -UseSsl ^ | ||