大家在使用send-mailmessge 編寫一些腳本的時候一般會使用匿名發送的方式,如下所示:
send-mailmessage -to "[email protected]" -from "[email protected]" -subject "mailtest" -SmtpServer mail.contoso.com
但是在smtpserver禁止匿名發送的情況下,應該怎麼辦呢?好多人說可以調用-credential參數。
但是在控制台預設輸入-credential一般會彈出視窗提示輸入密碼,沒辦法調用到腳本裡。有沒有一種法可以将密碼進行處理呢?
舉例說明:
$password = convertto-securestring "password.2013" -asplaintext -force
$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist "test",$password
send-mailmessage -to "[email protected]" -from "[email protected]" -subject "mailtest" -credential $cred -SmtpServer mail.contoso.com
這樣可以很完美的調用一個使用SMTP驗證的郵件發送腳本。
本文轉自handsome7038 51CTO部落格,原文連結:http://blog.51cto.com/lixiaosong/1322643