PowerShell Script to Send Email

### Variables section ###
$fromaddress = "admin@kimconnect.com"
$toaddress = "orders@kimconnect.com"
$bccaddress = ""
$CCaddress = ""
$Subject = "EDI Incoming Notification"
$body = "Incoming order has been received and our systems have imported it into the ERP system."
$attachment = "\\FILESERVER01\IT\scripts\EDI-Orders.xls"
$attachment2 = "\\FILESERVER01\IT\scripts\EDI-Summary.xls"
$smtpserver = "kimconnect.mail.protection.outlook.com"

### Sending via SMTP ###
$message = new-object System.Net.Mail.MailMessage
$message.From = $fromaddress
$message.To.Add($toaddress)
$message.CC.Add($CCaddress)
$message.Bcc.Add($bccaddress)
$message.IsBodyHtml = $True
$message.Subject = $Subject
$message.Attachments.Add($attachment)
$message.Attachments.Add($attachment2)
$message.body = $body
$smtp = new-object Net.Mail.SmtpClient($smtpserver)
$smtp.Send($message)

Leave a Reply

Your email address will not be published. Required fields are marked *