Last active
June 21, 2021 09:31
-
-
Save mkojoa/b44af45ce8b26ac53440ca08f4a2e2cb to your computer and use it in GitHub Desktop.
sending email with 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
$emailSmtpUser = "" | |
$emailSmtpPass = "" | |
$emailFrom = "persol.demo@gmail.com" | |
$emailTo = "michaelameyaw7@gmail.com" | |
$emailcc="michael.ameyaw@persol.net" | |
$emailMessage = New-Object System.Net.Mail.MailMessage($emailFrom,$emailTo) | |
$emailMessage.cc.add($emailcc) | |
$emailMessage.Subject = "UMB Test Email" | |
$emailMessage.Body = "umb test body" | |
$securestring = $emailSmtpPass | ConvertTo-SecureString -AsPlainText -Force | |
$SMTPClient = New-Object System.Net.Mail.SmtpClient("smtp.gmail.com",587) | |
$SMTPClient.EnableSsl = $true | |
$SMTPClient.UseDefaultCredentials = $false | |
$smtpClient.DeliveryMethod = [Net.Mail.SmtpDeliveryMethod]::Network; | |
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($emailSmtpUser,$securestring); | |
try { | |
$SMTPClient.Send($emailMessage) | |
} | |
catch [System.Exception] { | |
write-host $_.Exception | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment