powershell send email

#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)

你可能感兴趣的:(powershell send email)