Skip to content

Instantly share code, notes, and snippets.

@glallen01
Last active December 23, 2015 00:29
Show Gist options
  • Save glallen01/6553636 to your computer and use it in GitHub Desktop.
Save glallen01/6553636 to your computer and use it in GitHub Desktop.
PowerShell Email
$smtp = new-object Net.Mail.SmtpClient("mail.example.com")
if( $Env:SmtpUseCredentials -eq "true" ) {
$credentials = new-object Net.NetworkCredential("username","password")
$smtp.Credentials = $credentials
}
$objMailMessage = New-Object System.Net.Mail.MailMessage
$objMailMessage.From = "script@mycompany.com"
$objMailMessage.To.Add("you@yourcompany.com")
$objMailMessage.Subject = "eMail subject Notification"
$objMailMessage.Body = "Hello world!"
$smtp.send($objMailMessage)
# http://stackoverflow.com/questions/36498/how-do-i-send-email-from-the-command-line
$EmailFrom = “yourgmailadress@gmail.com”
$EmailTo = “destination@somedomain.com”
$Subject = “The subject of your email”
$Body = “What do you want your email to say”
$SMTPServer = “smtp.gmail.com”
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“usr”, “pass”);
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
#http://www.howtogeek.com/120011/stupid-geek-tricks-how-to-send-email-from-the-command-line-in-windows-without-extra-software/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment