2023-06-12

[PowerShell]小練習發送郵件含附件

剛出來的時候一直想玩沒空玩,現在重新學習
#####定義變量#####
$fromaddress = "mailuser@ace.com.tw"
$toaddress = "yolin_chen@ace.com.tw"
$Subject = “資訊安全檢查作業_特權帳號”
$body = get-content “C:\GPOReport.html”
#$attachment = “C:\GPOReport.html”
$smtpserver = "請填入SMTP IP Address"
##################################
$message = new-object System.Net.Mail.MailMessage
$message.From = $fromaddress
$message.To.Add($toaddress)
$message.IsBodyHtml = $True
$message.Subject = $Subject
#$attach = new-object Net.Mail.Attachment($attachment)
#$message.Attachments.Add($attach)
$message.body = $body
$smtp = new-object Net.Mail.SmtpClient($smtpserver)
$smtp.Send($message)

################################################# ##

沒有留言:

張貼留言