Created
April 11, 2024 00:24
-
-
Save yukoff/f990e3daf4fbac2eab1e7fceaeaeeb6a to your computer and use it in GitHub Desktop.
Example PowerShell script to send SMTP emails from Windows
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
# curl / wget are aliases for Invoke-WebRequest | |
$ip = Invoke-WebRequest -Uri https://ifconfig.co -ContentType "text/plain" -UserAgent curl | |
$hostname = hostname | |
$EmailFrom = "no-reply@$hostname" | |
$EmailTo = "[email protected]" | |
$Subject = "Remote address" | |
$Body = "Current IP address: $ip" | |
$SMTPServer = "smtp.mailgun.org" | |
$SMTPPort = 587 | |
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, $SMTPPort) | |
$SMTPClient.EnableSsl = $true | |
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential( | |
"login", | |
"password" | |
); | |
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment