#mail server configuration
$smtpServer = ""
$smtpUser = ""
$smtpPassword = ""
#create the mail message
$mail = New-Object System.Net.Mail.MailMessage
#set the addresses
$MailAddress=""
$MailtoAddress=""
$mail.From = New-Object System.Net.Mail.MailAddress($MailAddress)
$mail.To.Add($MailtoAddress)
#set the content
$mail.Subject = ""
$mail.Priority = ""
$mail.Body = ""
$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)
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/winsonyuan/archive/2011/01/12/6132172.aspx
本文介绍如何使用PowerShell配置邮件服务器并发送带有附件的电子邮件。通过设置SMTP服务器、用户名及密码,创建邮件消息对象,指定发件人和收件人地址,设定邮件主题和正文内容,最后附上文件附件并发送邮件。

1058

被折叠的 条评论
为什么被折叠?



