邮件发送附件

 

#定义邮件服务器
$smtpServer = "mail.163.com"
$smtpUser = "[email protected]"
$smtpPassword = "password"
$mail = New-Object System.Net.Mail.MailMessage

#定义发件人邮箱地址、收件人邮箱地址
$MailAddress="[email protected]"
$MailtoAddress="[email protected]"
$mail.From = New-Object System.Net.Mail.MailAddress($MailAddress)
$mail.To.Add($MailtoAddress)


 #定义邮件标题、优先级和正文、附件
$mail.Subject = "test";
$mail.Priority  = "High"
$mail.Body = "testttt"
$Afile = "e:\CSV-Export.rar"
$smtp = New-Object System.Net.Mail.SmtpClient -argumentList $smtpServer
$smtp.Credentials = New-Object System.Net.NetworkCredential -argumentList $smtpUser,$smtpPassword
$attachment = new-Object System.Net.Mail.Attachment -ArgumentList $Afile
$mail.Attachments.Add($attachment)
$smtp.Send($mail)
$attachment.dispose()

 

你可能感兴趣的:(邮件发送附件)