Created
April 29, 2019 13:28
-
-
Save tuck1s/47756840f04a70e3e798e189a7473fea to your computer and use it in GitHub Desktop.
Windows PowerShell Script to send email via SparkPost using TLS 1.2 and API key credentials
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
# The Win 10 commandlet defaults to TLS 1.0 which is deprecated as incecure! (see https://www.sparkpost.com/blog/tls-v1-0-deprecation/) | |
# Make Windows negotiate higher TLS version as follows: | |
[System.Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
# Build a Credential object containing SparkPost API key as password | |
$pwd = ConvertTo-SecureString "<<Your API KEY HERE>>" -AsPlainText -Force | |
$creds = New-Object System.Management.Automation.PSCredential ("SMTP_Injection", $pwd) | |
# Send. This is using the SparkPost EU service. If you are using the US service, change SmtpServer to be smtp.sparkpostmail.com. | |
Send-MailMessage -From "[email protected]" -To [email protected] -Subject "Hello World" -Body "Here it is" -SmtpServer smtp.eu.sparkpostmail.com -Port 587 -Credential $creds -UseSsl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment