Skip to content

Instantly share code, notes, and snippets.

@d4rkeagle65
Created June 9, 2020 16:05
Show Gist options
  • Save d4rkeagle65/001e2d1c2941d41c2ec2b6360bb3a9b6 to your computer and use it in GitHub Desktop.
Save d4rkeagle65/001e2d1c2941d41c2ec2b6360bb3a9b6 to your computer and use it in GitHub Desktop.
Send an email with or without SSL via powershell.
# Sender and Recipient Info
$MailFrom = "[email protected]"
$MailTo = "[email protected]"
# Sender Credentials
$Username = ""
$Password = ""
# Server Info
$SmtpServer = ""
$SmtpPort = "25"
# Message stuff
$MessageSubject = "Test"
$Message = New-Object System.Net.Mail.MailMessage $MailFrom,$MailTo
$Message.IsBodyHTML = $true
$Message.Subject = $MessageSubject
$Message.Body = "Test"
# Construct the SMTP client object, credentials, and send
$Smtp = New-Object Net.Mail.SmtpClient($SmtpServer,$SmtpPort)
$Smtp.EnableSsl = $true
$Smtp.Credentials = New-Object System.Net.NetworkCredential($Username,$Password)
$Smtp.Send($Message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment