Hi, Peter_1985
The snippet below works for me. For your reference: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-7.3
PowerShell ps = PowerShell.Create();
ps.AddScript("$UserName = '******@XXX.com'");
ps.AddScript("$Password = ConvertTo-SecureString passwordtoken -AsPlainText –Force");
ps.AddScript("$cred = New-Object System.Management.Automation.PSCredential($UserName,$Password) ");
ps.AddScript("Send-MailMessage -From '******@XXX.com' -To '******@XXX.com' -Subject 'Test mail' -SmtpServer 'smtp.XXX.com' -Credential $cred");
ps.Invoke();
Best regards,
Minxin Yu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.