Send E-Mails with PowerShell using Modern Auth. (OAuth)
You are currently using Send-MailMessage
with Basic Auth. and want to transition to Modern Authentication?
May this PowerShell Module assists you, without having to rewriting your routine with Microsoft Graph directly.
- Provides
Send-MailMessage
translation to Microsoft Graph - Supports SMTP with OAuth2 (Modern Auth, SASL XOAUTH2)
Send emails in PowerShell via Graph API, or SMTP (MailKit) with Modern Auth (OAuth) support.
Installation
Send-ModernMailMessage
is a modern PowerShell cmdlet for sending emails. It is part of the ModernMailTools module, designed as an improved and more flexible alternative to the legacy Send-MailMessage
cmdlet.
- Docs: Send-ModernMailMessage
1 2 3 4 5 6 7 8 9 10 11 |
|
Authentication
It supports flexible authentication options to fit different use cases, whether you're sending mail as a user or from an application.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Protocols
Additionally, it supports different protocol options, allowing you to choose between Microsoft Graph API or traditional SMTP, depending on your environment or preference.
1 2 3 4 5 6 7 |
|
Summary
Send-ModernMailMessage
provides a modern, flexible way to send emails in PowerShell using either SMTP or Microsoft Graph API. While there are other solutions available, some felt too complex or didn’t match my goal of easily switching between methods. It supports both user and app authentication, includes a legacy alias for Send-MailMessage, and is easy to install. Though not every command feature is complete yet, creating this module was a valuable process and leaves room for further improvement.
Wishing you all a good day!
References:
- Authenticate an IMAP, POP or SMTP connection using OAuth
- Basic access authentication
- Send-MgUserMail
Alternatives:
- PoshMailKit
- Send-MailKitMessage
- Mailozaurr
- SendEmail
- Send-O365MailMessage
- Test-SmtpClientSubmission
- Send-IgugaMailMessage
- Send-EwsMailMessage