任务完成后批处理文件发送邮件

时间:2016-06-15 05:28:38

标签: email powershell batch-file cmd

我正在尝试在完成批处理文件后通过PowerShell发送电子邮件。 我的批处理文件是:

@echo on

setlocal EnableDelayedExpansion

set folderpath= "mypath"

@echo on

cd %folderpath%

for /f %%a in ('dir /b "%folderpath%\*.txt"') do (
   set "fname=%%~na"
   ren "%%a" "!fname:~0,-33!.txt"
)

%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe C:\myfolder\my_powershell_script.ps1

pause

我的PowerShell脚本是:

Set-ExecutionPolicy -Scope LocalMachine Unrestricted

$smtpServer = "my server"

$msg = New-Object Net.Mail.MailMessage
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)

$msg.From = ("mail from")
$msg.To.Add("mail to")
$msg.Subject = "subject"
$msg.Body = "body"

$smtp.Send($msg)

我收到一条错误消息:

  

异常调用发送1个参数失败发送邮件

任何帮助?

0 个答案:

没有答案