Exchange online Send Mail with Powershell

Scriptler içinde Exchange Online kullanarak mail atma işlemlerini yapmak için aşağıdaki kod yapısı kullanabilir.

$username = “username@domain.com”
$password = “Ak!20212024*-“

$sendMail = “username@domain.com”

$sstr = ConvertTo-SecureString -string $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential -argumentlist $username, $sstr
$body = “This is a test email”
Send-MailMessage -To $sendMail -from $username -Subject ‘Parola Reset Test’ -Body $body -BodyAsHtml -smtpserver smtp.office365.com -usessl -Credential $cred -Port 587