如果PowerShell是可用,Send-MailMessage命令行是一個單行命令,可以很容易地從一個批處理文件調用處理郵件通知。以下是您要在批處理文件中包含的用於調用PowerShell腳本的行的示例(%xVariable%
是您可能想要從批處理文件傳遞到PowerShell腳本的變量):
- [BATCH FILE] -
:: ...your code here...
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -windowstyle hidden -command C:\MyScripts\EmailScript.ps1 %xVariable%
以下是你可能會在您的PowerShell腳本示例(您必須包括PARAM線在你的腳本,如果你提供從批處理文件傳遞%xVariable%
的第一個非目標行:
- [PowerShell腳本] -
Param([String]$xVariable)
# ...your code here...
$smtp = "smtp.[emaildomain].com"
$to = "[Send to email address]"
$from = "[From email address]"
$subject = "[Subject]"
$body = "[Text you want to include----the <br> is a line feed: <br> <br>]"
$body += "[This could be a second line of text]" + "<br> "
$attachment="[file name if you would like to include an attachment]"
send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -Attachment $attachment -Priority high
[這](http://www.msexchange.org/articles/sending-email-without-client.html)可能的幫助。它說明了如何通過命令行或使用telnet做 – vaichidrewar 2012-01-27 19:34:54
沒有目錄\的Inetpub \ mailroot \皮卡,所以攝取方法不起作用。我沒有被允許在機器上安裝任何軟件,所以blat方法不起作用。我不想手動執行此操作,所以telnet方法不起作用。而我沒有ASP,所以這種方法不起作用。任何其他想法? [從批處理文件發送郵件]的 – user448810 2012-01-27 19:46:44
可能重複(http://stackoverflow.com/questions/709635/sending-mail-from-batch-file) – 2015-08-18 17:00:47