How to send a simple email from a Windows batch file?

前端 未结 6 1556
醉酒成梦
醉酒成梦 2020-12-07 21:35

I\'m running Windows 2003 Service Pack 2. I have a batch file that runs on demand. I want to have an email sent every time the batch file runs. The email is simple, just a s

6条回答
  •  甜味超标
    2020-12-07 22:03

    It works for me, by using double quotes around variables.

    I am using batch script to call powershell Send-MailMessage

    Batch Script:send_email.bat

    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -command 'E:\path\send_email.ps1
    

    Pwershell Script send_email.ps1

    Send-MailMessage -From "noreply@$env:computername" -To '' -Subject 'Blah Blah' -SmtpServer  'smtp.domain.com'  -Attachments 'E:\path\file.log' -BODY "Blah Blah on Host: $env:computername "
    

提交回复
热议问题