How do I pass Login credentials into Send-MailMessage which is in HTML format

Hi ! How do I pass Login credentials into the script? The script is as below.

Please advise.

Thank you

Send-MailMessage -To “peter@123.com” -From “peter@123.com” -Subject “Report $CurrentTime” -Attachments $ListOfAttachments -BodyAsHTML -body $HTMLmessage -priority Normal -Credential $mycreds -SmtpServer “10.66.10.25” -Port 25

Peter,
Welcome to the forum. :wave:t4:

In the simplest case you store it in the variable $mycreds wtih the cmdlet

If you want to do it properly and secure you may use the new SecretManagement module from MSFT

Hi ! Olaf,

Thank you.
Do you have an example for Send-MailMessage using SecretManagement?

Best place to start with SecretManagement is here SecretManagement and SecretStore are Generally Available - PowerShell Team (microsoft.com)

Hi ! Kvprasoon,

Thank you.