magritton
4/30/2014 - 7:34 PM

Sending email through powershell

Sending email through powershell

$finished = Get-Date
#SMTP server name
$smtpServer = "OPWEXC02.opwftg.com"

#Creating a Mail object
$msg = new-object Net.Mail.MailMessage

#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpServer)

#Email structure 
$msg.From = "no_reply@opwftg.com"
$msg.To.Add("mikegritton@opwftg.com")
$msg.subject = "EDM Scan Finished"
$msg.body = "SharePoint SiteMap successfully created. Start Time: " + $started.ToString() + " End time: " + $finished.ToString() + ". Files scanned: " + $Cnt.ToString()

#Sending email 
$smtp.Send($msg)