your home for end-user virtualization!

How to send an email attachement within a script using Windows Powershell

$filename = “c:\results.csv”
$smtpServer = “smtpserver.domain.local”
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($filename)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = “fromaddress@domain.local”
$msg.To.Add(”toaddress@domain.local”)
$msg.Subject = “Nightly Log File”
$msg.Body = “The nightly log file is attached”
$msg.Attachments.Add($att)
$smtp.Send($msg)

Then call the script using

./email.ps1

Search

Categories