Date created: Sunday, December 11, 2011 8:44:09 PM. Last modified: Thursday, December 13, 2012 11:41:20 AM

Email Attachment with Powershell

##Variables:
$SMTPServer = "mxserver.example.com"
$FromAddress = "powshell@example.com"
$ToAddress = "reports@example.com"
$Subject = "Monthly Stats"
$Body = "Monthly stats attached"
##Compile SMTP message and send:
$SMTPMessage = New-Object System.Net.Mail.MailMessage $FromAddress, $ToAddress, $Subject, $Body
$Attachment = New-Object Net.Mail.Attachment("C:\Dir1\Stats.txt")
$SMTPMessage.Attachments.Add($Attachment)
$Attachment = New-Object Net.Mail.Attachment("C:\Dir2\Stats.sv")
$SMTPMessage.Attachments.Add($Attachment)
$SMTPClient = New-Object System.Net.Mail.SMTPClient $SMTPServer
$SMTPClient.Send($SMTPMessage)

Previous page: Disconnected Mailboxes
Next page: Exchange Certificate