[Powershell] 利用cmdlet 發出電郵

有時為了確保schedule job 順利執行, 通常最後會加入通知功能. 若在command prompt, 須要靠其他console app, 而在Powershell 中, 則已經內建了電郵功能, 叫用方法如下:

# Email related settings.
$emailSmtpServer="smtp.aaa.com"
$emailFromAddress="[email protected]"
$emailToAddress="[email protected]"
$emailSubject="This is title"
$emailContent="This is body"

Send-MailMessage -to $emailToAddress -from $emailFromAddress -subject $emailSubject -body $emailContent -smtpServer $emailSmtpServer -attachments $logFilePath

 

About C.H. Ling 260 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.