Skip to content

Instantly share code, notes, and snippets.

@ernestohs
Created February 10, 2015 00:36
Show Gist options
  • Save ernestohs/b0519b3ec12855bdc9ff to your computer and use it in GitHub Desktop.
Save ernestohs/b0519b3ec12855bdc9ff to your computer and use it in GitHub Desktop.
PowerShell: Send Email
$from = "Jhon Doe <jhon@doe.com>"
$subject = "This is my subject"
$body = @"
<strong>Cool html content</strong>
"@
$smtpServer = "smtp.server.com"
$user = "smtpuser"
$password = "secretword"
$message = New-Object System.Net.Mail.MailMessage
$message.To.Add("this@guy.com")
$message.From = $from
$message.Subject = $subject
$message.IsBodyHTML = $true
$message.Body = $body
$message.Priority = [System.Net.Mail.MailPriority]::High
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Credentials = New-Object System.Net.NetworkCredential($user, $password)
$smtp.Send($message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment