通过电子邮件发送powershell输出

时间:2012-10-18 13:37:55

标签: powershell

我有一个powershell脚本,它使用Write-Output来显示每个循环的结果。 我需要通过电子邮件发送输出,之前使用sendemail.exe执行此操作,如下所示

cscript //nologo script.vbs 2>&1 | sendEmail.exe -t mail@blah.co.uk -u "subject blah" -f mail@blah.co.uk -s smtpserver1.mail.co.uk

我无法使用powershell,因为当我运行.ps1脚本时,它会将输出写入当前控制台,而不会将其传递给sendemail.exe应用程序。我是否需要不同的cmdlet,或者将电子邮件功能编写到脚本中是否更简单?

2 个答案:

答案 0 :(得分:5)

不要在PowerShell上使用sendmail.exe。在PowerShell 2.0及更高版本中,在脚本本身中使用Send-MailMessage。将“输出”捕获到变量以使用-Body参数传递。

答案 1 :(得分:3)

如果您使用的是powershell v2或v3,为什么不使用此本机cmdlet?

send-mailmessage

相关问题