Hey everyone! I'm trying to figure out how to send emails through PowerShell using a Microsoft account. The issue I'm running into is an authentication error every time I try, even though I'm sure that my password is correct and there's no MFA (Multi-Factor Authentication) set up for this account. Any ideas on what might be going wrong?
5 Answers
I recommend avoiding Send-MailMessage since it's deprecated. Instead, using Microsoft Graph with OAuth is the way to go. You'd need to create an app registration and possibly a self-signed certificate too. Here's a link to a detailed guide on that: [Creating a self-signed certificate](https://learn.microsoft.com/en-us/entra/identity-platform/howto-create-self-signed-certificate).
Using the Microsoft Graph API is a solid approach! I created a PowerShell module for it. Just make sure to have the Microsoft.Graph module installed and connect with the right scope (Mail.Send). You can check out my module [here](https://github.com/noahpeltier/PSGraphMail).
To help with your issue, I'd need to see some code. Otherwise, it's hard to guess what's wrong. Are you using the correct SMTP settings?
If it's a business or school account, OAuth2 might be required, which makes PowerShell authentication tricky. Sharing your SMTP settings and the sending code would be great for us to troubleshoot.
Basic authentication is often blocked on Microsoft accounts. You may want to use an OAuth token through app registration for sending emails. Be careful with permissions!
Got it, I'll share my code. But just to clarify, my account is personal, not business.