Created
October 20, 2016 15:35
-
-
Save conrjac/cfb07db029d71f0cac16b2f11dd6e97f to your computer and use it in GitHub Desktop.
PowerShell Send Email from Exchange
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "[email protected]" | |
$msg.ReplyTo = "[email protected] (Maybe noreply?)" | |
$msg.To.Add("[email protected]") | |
$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