PowerShell使用SMTP發送郵件


$smtpServer = "smtp.exmail.qq.com"
$smtpUser = "xxxxx@qq.com"
$smtpPassword = "xxxxxxxxxxxxxx"
#create the mail message
$mail = New-Object System.Net.Mail.MailMessage
#set the addresses
$MailAddress="xxxxx@qq.com"
$MailtoAddress="xxxxx11111111@qq.com"
$mail.From = New-Object System.Net.Mail.MailAddress($MailAddress)
$mail.To.Add($MailtoAddress)
#set the content
$mail.Subject = "Hello PowerShell";
$mail.Priority = "High"
$mail.Body = "Hello Powershell" 
$filename="D:\1.txt"	#add file
$attachment = new-Object System.Net.Mail.Attachment($filename)
$mail.Attachments.Add($attachment)
#send the message
$smtp = New-Object System.Net.Mail.SmtpClient -argumentList $smtpServer
$smtp.Credentials = New-Object System.Net.NetworkCredential -argumentList $smtpUser,$smtpPassword
$smtp.Send($mail)

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM