Send SMTP E-mail using PowerShell

Modified on Thu, 8 May at 12:00 PM

Without authentication:

$mailserver = "smtp.abc.com"
$smtpport = 25
$from = "user@domain.com"
$to = "user@abc.com"

Send-MailMessage -SmtpServer $mailserver -Port $smtpport -From $from -To $to -Subject "SMTP Test" -Body "This is a test message"

Without authentication with SSL:

$mailserver = "smtp.abc.com"
$smtpport = 25
$from = "user@domain.com"
$to = "user@abc.com"

Send-MailMessage -SmtpServer $mailserver -Port $smtpport -From $from -To $to -Subject "SMTP Test" -Body "This is a test message" -UseSsl

Bulk:

# Must be in PowerShell Core (7+)
$mailserver = "smtp.abc.com"
$smtpport = 25
$from = "user@domain.com"
$to = "user@abc.com"
$count = 500

1..$count | ForEach-Object -Parallel {
    $randomNumber = Get-Random -Minimum 100000 -Maximum 999999
    $subject = "$randomNumber SMTP Test"
    Send-MailMessage -SmtpServer $using:mailserver -Port $using:smtpport -From $using:from -To $using:to -Subject $subject -Body "This is a test message"
} -ThrottleLimit 20

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article