I have this code to send email with attachment:-
$encpassword = convertto-securestring -String "*****" -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "***@***", $encpassword
Connect-PnPOnline -Url $sourceWebURL -Credentials $cred
Send-MailMessage -to "" -from "" -Credentials $cred -bcc "" -Port "587" -UseSSL "true" -Subject "subject" -Body "<b>1</b><br><b>2</b>" -BodyAsHtml -SmtpServer "smtp.office365.com" -Attachments "C:\s.csv"
but based on the documentation's warning that Send-MailMessage
is obsolete @ https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-7.3
and at the same time using Send-PnPMail
does not support sending attachments @ https://pnp.github.io/powershell/cmdlets/Send-PnPMail.html .
so my question is how we can send an email using power shell using a supported/recommended approach which allow us to attach a file.
Thanks