Have you looked at Send-MailMessage? It sends emails with optional attachments.
How to create Powershell script to send an email to all email addresses listed in a file and send an attachment called via a DOS batch file.
Is there a way to do this?
Prefer that the Powershell script uses the logged on credentials rather than storing the credentials in the script.
Windows for business | Windows Server | User experience | PowerShell
2 answers
Sort by: Most helpful
-
-
Rich Matheisen 47,901 Reputation points
2021-03-23T18:35:55.53+00:00 The Send-MailMessage may be able to use the credentials of the account under which it's been run, but I've never tried it, and there's no parameter that you can use to tell it to.
The Send-MailMessage cmdlet is build on the System.Net.Mail.SMTPClien class, and that has a "UseDefaultCredentials" property. If necessary you can always use the SMTPClient class in your script.
However, the Send-MailMessage cmdlet (and the SMTPClient class) have been deprecated because neither of them use the latest TLS version -- and there are no plans to add that ability -- so using SSL may not be possible, and that will expose your user/password on the network (they're only Base64 encoded so it's extremely easy to "decode").
You may be better off looking at the MailKit module. Have a look here for a good bit of information: powershell-email