Created
May 11, 2023 02:26
-
-
Save DovieW/2c7e0c5037ccae0df921c32b20fb2f39 to your computer and use it in GitHub Desktop.
Send Email via PowerShell
This file contains 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
$to = "user1@email.com,user2@email.com" # comma separate multiple recipients | |
$from = "sender@email.com" | |
$subject = "subject goes here" | |
$body = "message body goes here" | |
$smtpServer = "smtp.gmail.com" | |
$smtpClient = New-Object Net.Mail.SmtpClient($smtpServer, 587) # port 25 for non SSL, port 587 for SSL | |
$smtpClient.EnableSsl = $true # set to $true for SSL | |
$smtpClient.Credentials = New-Object System.Net.NetworkCredential("username", "password") | |
# use this line instead to use credentials of the user running the script | |
# $smtpClient.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials | |
$smtpClient.Send($from, $to, $subject, $body) | |
#Run it with: powershell -ExecutionPolicy Bypass -File "path/to/send_email.ps1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment