Last active
June 11, 2021 09:14
-
-
Save frandi/d9dbbc0bd3873f0bf9cf727bf8c54c27 to your computer and use it in GitHub Desktop.
Send email from PowerShell (SMTP Test)
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
# install the module (it only needs to be done once) | |
Install-Module -Name "Send-MailKitMessage" -Scope CurrentUser | |
$SMTPServer = "smtp.gmail.com" | |
$Port = 587 | |
$Username = "" | |
$Password = "" | |
$Credential=[System.Management.Automation.PSCredential]::new($Username, (ConvertTo-SecureString -String $Password -AsPlainText -Force)) | |
$From = "[email protected]" | |
$RecipientList=[MimeKit.InternetAddressList]::new() | |
$RecipientList.Add([MimeKit.InternetAddress]"[email protected]") | |
$CCList=[MimeKit.InternetAddressList]::new() | |
$CCList.Add([MimeKit.InternetAddress]"[email protected]") | |
$Subject = "SMTP Test" | |
$TextBody = "This email was sent from PowerShell" | |
$HTMLBody = "This email was sent from <b>PowerShell</b>" | |
$AttachmentList=[System.Collections.Generic.List[string]]::new() | |
$AttachmentList.Add("c:\path\to\attachment") | |
Send-MailKitMessage -SMTPServer $SMTPServer -Credential $Credential -Port $Port -From $From -RecipientList $RecipientList -Subject $Subject -TextBody $TextBody |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment