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)

  

posted on 2016-04-01 11:10  Tea_Ing  阅读(3418)  评论(0编辑  收藏  举报

导航