Skip to content

Instantly share code, notes, and snippets.

@conrjac
Created October 20, 2016 15:35
Show Gist options
  • Save conrjac/cfb07db029d71f0cac16b2f11dd6e97f to your computer and use it in GitHub Desktop.
Save conrjac/cfb07db029d71f0cac16b2f11dd6e97f to your computer and use it in GitHub Desktop.
PowerShell Send Email from Exchange
function sendLoggingEMail($subject,$message){
Write-Host "Sending Email"
#Exchange Server
$exchangeServer = "Exchange Address e.g webmail.domain.tld"
#Creating a Mail object
$msg = new-object Net.Mail.MailMessage
#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($exchangeServer)
#Email structure
$msg.From = "example@domain.tld"
$msg.ReplyTo = "example@domain.tld (Maybe noreply?)"
$msg.To.Add("example@domain.tld")
$msg.subject = $subject
$msg.body = $message
#Sending email
$smtp.Send($msg)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment