Have you tried using the Send-MgUserMail cmdlet?
What license do I need to be able to send emails through Microsoft Graph via an unattended desktop app?
Context: I'm a developer who writes console programs that scrape web sites. When an event occurs, I send an email to myself. MS recently turned off basic authentication. No sample program anywhere on the internet works to send via Microsoft Graph or other (no Twilio Sendmail or 3rd party service please. MS blocks them).
Question: What Azure service or license do I need to be able to send emails from an unattended Windows Desktop program to myself?
This web site says I need a license" https://zimmergren.net/sending-e-mails-using-microsoft-graph-using-dotnet/
I have a MS Office 365 Subscription
I have an entra application with client secrets and API Permissions for Mail.Read and Mail.Send
I have no problem authenticating. It's when I do "mail.send" when it says "Unauthorized"
Tried and Failed:
- I've set up a MS Entra Client Secret.
- I've tried sending with PublicClientApplicationBuilder and got this on
var request = new HttpRequestMessage(HttpMethod.Post, "https://graph.microsoft.com/v1.0/me/sendMail")
{ Content = requestContent };
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
var response = await httpClient.SendAsync(request);`
Unauthorized
{"error":{"code":"OrganizationFromTenantGuidNotFound","message":"The tenant for tenant guid '00000000-f40e-4889-977c-67abc6b1ea17' does not exist.","innerError":{"oAuthEventOperationId":"ade9420d-f3ba-4a2f-bdf9-cc02f213455d","oAuthEventcV":"3Z1lS49nvGfZCpcrkoKZnQ.1.1","errorUrl":"https://aka.ms/autherrors#error-InvalidTenant","requestId":"670f3d80-8c63-4353-9135-4ff203e7e78f","date":"2025-01-10T21:14:42"}}}
Yes, the tenant ID is correctly set