1. 程式人生 > 實用技巧 >powershell中使用Send-MailMessage傳送郵件

powershell中使用Send-MailMessage傳送郵件

在powershell中我們可以使用Send-MailMessage傳送郵件,一般都是有這個命令的

筆者的總結是鑑於公司的環境的,大家在借鑑時,需要根據自己的實際情況進行修改

1、你筆者測試的格式如下(對於一封郵件來說,至少是需要有Subject的,也即是主題) 、另smtp伺服器是必須要指定的:

Send-MailMessage -SmtpServer "1.2.3.4" -to "[email protected]" -From "[email protected]" -Subject "Mail test"
Send-MailMessage -SmtpServer "1.2.3.4" -to "[email protected]" -From "
[email protected]" -Subject "My blogs" -Body "https://www.cnblogs.com/5201351"

2、一般一封郵可能還需要用到一些如下的選項你:

#也可以帶上附件,不過有時可能會有附件大小的限制
Send-MailMessage -SmtpServer "1.2.3.4"  -to "[email protected]"  -From "[email protected]"  -Subject "A" -Body "B" -Attachments "C:\c.txt"

3、還有-Cc和-Bcc也是比較常用的選項,可以根據實際情況使用 !另如果有多個郵箱號,中間以逗號,隔開即可!

尊重別人的勞動成果 轉載請務必註明出處:

https://www.cnblogs.com/5201351/p/13622053.html