WELCOME

2009年1月21日 星期三

Send mail with powershell

原文

#mail server configuration
$smtpServer = "smtpServer"
$smtpUser = "smtpUse"
$smtpPassword = "smtpPassword "

#create the mail message
$mail = New-Object System.Net.Mail.MailMessage

#set the addresses
$MailAddress="MailAddress"
$MailtoAddress="MailtoAddress"
$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 = "Sending mail is easy!"
$filename="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)



$smtpServer = "smtpServer" #待发邮件服务器
$smtpUser = "smtpUse" #待发邮件用户名
$smtpPassword = "smtpPassword " #用户名密码

=============================
$MailAddress="MailAddress" #发送方的邮件地址
$MailtoAddress="MailtoAddress" #邮件接收方的地址 (看4楼出问题的截图,你这里没有指定接收方是谁呢?!)

$mail.To.Add($MailtoAddress) #添加这个接受方的地址

沒有留言:

張貼留言