Test SMTP/e-mail Server relay with PowerShell

To test your SMTP/e-mail Server relay using Powershell, execute:

Send-MailMessage –From mailbox1@domain.com –To alejandra.restrepo@mailbox1@domain.com –Subject “Test PowerShell” –Body “Test E-mail (body)” -SmtpServer smtp-relay.gmail.com -port 25

You can use a powershell script .ps1:

$EmailFrom = "sender@gmail.com"
$EmailTo = "recipient@email.com"
$Subject = "Subject"
$Body = "Body"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("sender@gmail.com", "YourGmailPassword");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

If you have problems with the execution policy, run:

Powershell.exe -executionpolicy remotesigned -File C:\Users\myusername\myfile.ps1

Comentarios