Created
June 9, 2020 16:05
-
-
Save d4rkeagle65/001e2d1c2941d41c2ec2b6360bb3a9b6 to your computer and use it in GitHub Desktop.
Send an email with or without SSL via powershell.
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
| # 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