Test O365 SMTP sending mail with PoweShell Script

You can send an mail from your o365 account so you can test your smtp seeting of O365 to see if settings are okay or not. You can also use for gmail as well.

$emailSmtpServer = “smtp.office365.com”
$emailSmtpServerPort = “587”
$emailSmtpUser = “e-mail”
$emailSmtpPass = “Password”

$emailFrom = “xyz”
$emailTo = “xyz”
$emailcc=”xyz”

$emailMessage = New-Object System.Net.Mail.MailMessage( $emailFrom , $emailTo )
$emailMessage.cc.add($emailcc)
$emailMessage.Subject = “subject”

$emailMessage.IsBodyHtml = $true #true or false depends

$emailMessage.Body = “body”

$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )
$SMTPClient.EnableSsl = $True
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential( $emailSmtpUser , $emailSmtpPass );
$SMTPClient.Send( $emailMessage )

Yazar hakkında

serdanaydin