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 “” -From “” -Subject “Report $CurrentTime” -Attachments $ListOfAttachments -BodyAsHTML -body $HTMLmessage -priority Normal -Credential $mycreds -SmtpServer “” -Port 25

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 (

Hi ! Kvprasoon,

Thank you.