邮件发送附件
#定义邮件服务器 $smtpServer = "mail.163.com" $smtpUser = "sys@163.com" $smtpPassword = "password" $mail = New-Object System.Net.Mail.MailMessage #定义发件人邮箱地址、收件人邮箱地址 $MailAddress="sys@163.com" $MailtoAddress="ll@163.com" $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()