27.8 C
Dubai
Wednesday, April 24, 2024

Send Emails using Microsoft Graph and Shared Mailboxes

Send Email from an Application using Microsoft Graph and Microsoft 365 shared mailbox without an logged in user.

Log into Exchange Admin center and create a shared mailbox.

.

Create an Enterprise Application

.
.
.

Choose Microsoft Graph

.

Choose Application

.

Add Mail.Send Permission

.

Grant Admin Consent

.

Grant Admin Consent Confirmation

.

Grant is successful

.

Create a Secret

.

Copy the secret and keep in a notepad

Collect your Client ID – Application (Client) ID

There are two steps – Take Token – then use the token to send email.

.

Use Postman to get Token.

grant_typeclient_credentials
client_id538cfed0-656d-4195-ae15-700467d946dc
client_secretCns8Q~M3WdNSgesDxrfb0i4_rBd0iCPrJg_kodjY
scopehttps://graph.microsoft.com/.default

Download Postman 64 Bit and install on Windows or Mac

.

Copy the Access Token – Take it without double quotes

.

Now lets POST on graph url to send some test emails. Put this as Headers

AuthorizationBearer REPLACE-WITH-TOKEN-VALUE-WITHOUT-QUOTES
Content-Typeapplication/json
.

{
    "message": {
        "subject": "Sending from Graph",
        "body": {
            "contentType": "Text",
            "content": "Sending from Graph using PostMan"
        },
        "toRecipients": [
            {
                "emailAddress": {
                    "address": "sathesh@azure365prox.com"
                }
            }
        ],
        "ccRecipients": [
            {
                "emailAddress": {
                    "address": "info@azure365pro.com"
                }
            }
        ]
    },
    "saveToSentItems": "false"
}
.
.

Email is generated

.

If the scope of permission is wide. In Enterprise scenario you can harden it using New-ApplicationAccessPolicy which i have explained in this article to reach attachments using Graph. Access Specific Office 365 Mailbox using Microsoft Graph – Azure365Pro.com

Satheshwaran Manoharan
Satheshwaran Manoharanhttps://www.azure365pro.com
Award-winning Technology Leader with a wealth of experience running large teams and diversified industry exposure in cloud computing. From shipping lines to rolling stocks.In-depth expertise in driving cloud adoption strategies and modernizing systems to cloud native. Specialized in Microsoft Cloud, DevOps, and Microsoft 365 Stack and conducted numerous successful projects worldwide. Also, Acting as a Technical Advisor for various start-ups.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

× How can I help you?