Invio mail tramite Office365 via Powershell
Per testare il sistema SMTP di Office365 è possibile usare powershell per spedire una mail.
Di seguito i cmdlets che permettono di autenticarsi a Office365 e spedire una mail con tanto di allegato:
$secpasswd = ConvertTo-SecureString “InsertPasswordHere” -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential (“MyEmail@domain.com”, $secpasswd)
Send-MailMessage -To "simon@domain.com" -Cc "simon@otherdomain.com" -Attachments "d:\logs\log1.txt","d:\logs\log2.txt","d:\logs\log3.log" -SmtpServer "smtp.office365.com" -Credential $mycreds -UseSsl "Backup Notification" -Port "587" -Body "This is an automatically generated message.
Your server backup has been successful.
Please remember to swap your hard drives when you return to the office for the continuing safety of your data
Best regards
Your Support Bot" -From "support@domain.com" -BodyAsHtml