I'm trying to set up a function in PowerShell to send emails using Gmail as the SMTP server for a side project. I've managed to get an app password, but I'm running into authentication issues because Send-MailMessage is deprecated. Does anyone know of any workarounds or can share a ready-to-use function? Alternatively, if there's another email provider I could use for sending emails based on certain script conditions that trigger every few hours, I'd love to hear suggestions! Thanks!
1 Answer
You might want to check out the Mailozaurr PowerShell module; it's based on MailKit and supports Gmail configurations really well. Another option is the Send-MailKitMessage module on GitHub. Here’s a simple setup:
```powershell
$Password = 'yourAppPassword' | ConvertTo-SecureString -AsPlainText -Force
$From = '[email protected]'
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $From, $Password
$MailSplat = @{ From = $From; To = '[email protected]'; Subject = 'Test Email'; Body = 'This is a test.'; SmtpServer = 'smtp.gmail.com'; Port = 587; UseSsl = $true; Credential = $Credential }
Send-MailMessage @MailSplat
```
Just remember to replace the placeholders with your actual data! Good luck!

Thanks for the suggestions! I’ll definitely try the Mailozaurr module. I've been having some trouble with GitHub actions, so fingers crossed this works better!