Skip to content

Instantly share code, notes, and snippets.

@msoler8785
Last active October 17, 2022 19:30
Show Gist options
  • Save msoler8785/64d438b31db6a8c807652cbc01e159e6 to your computer and use it in GitHub Desktop.
Save msoler8785/64d438b31db6a8c807652cbc01e159e6 to your computer and use it in GitHub Desktop.
How to send messages via SocketLabs SMTP
# Configure your message HTML here.
$bodyHtml = @"
<html>
    <head>
        <title>Hello!</title>
    </head>
    <body>
        <h2>Hello SocketLabs!</h2>
        <p>This is an example message.</p>
    </body>
</html>
"@

# From Sender
$from = "sender@example.com"

# To Recipient
$to = "recipient@example.com"

$subject = "Hello from PowerShell!"

# Can be port 25, 2525, or 587
$port = 587;
$server = "smtp.socketlabs.com"

# Put in your SMTP credentials here.
$username = "xxxxxxxxx"
$password = "xxxxxxxxx"

# Use this for unattended scripts to create the credential.
$secureString = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ($username, $secureString)

# Send the message
Send-MailMessage -To $to -BodyAsHtml $html -From $from -Subject $subject -SmtpServer $server -Port $port -Credential $credential -UseSsl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment