Thamara Kannan
Thamara Kannan

Reputation: 1

Event created successfully via Microsoft 365 API with application permissions, but email not sent to attendees despite permissions being enabled. Why?

import requests
import msal

# Microsoft Azure AD Credentials
CLIENT_ID = "*************"
CLIENT_SECRET = "**************"
TENANT_ID = "****************"
GRAPH_API_URL = "https://graph.microsoft.com/v1.0"

# Get Access Token using MSAL
app = msal.ConfidentialClientApplication(CLIENT_ID, authority=f"https://login.microsoftonline.com/{TENANT_ID}", client_credential=CLIENT_SECRET)
token_response = app.acquire_token_for_client(scopes=["https://graph.microsoft.com/.default"])

if "access_token" not in token_response:
    print("❌ Failed to get access token:", token_response)
    exit()

access_token = token_response["access_token"]
headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
}

# Define Meeting Data
meeting_data = {
    "subject": "Team Meeting",
    "body": {
        "contentType": "HTML",
        "content": "This is a scheduled Microsoft Teams meeting."
    },
    "start": {
        "dateTime": "2025-02-05T12:00:00",
        "timeZone": "UTC"
    },
    "end": {
        "dateTime": "2025-02-05T13:00:00",
        "timeZone": "UTC"
    },
    "location": {
        "displayName": "Microsoft Teams"
    },
    "attendees": [
        {
            "emailAddress": {
                "address": "[email protected]",
                "name": "Kannan M"
            },
            "type": "required"
        }
    ],
    "isOnlineMeeting": True,
    "onlineMeetingProvider": "teamsForBusiness"
}

USER_ID = "[email protected]"

# Create the Meeting Event
response = requests.post(f"{GRAPH_API_URL}/users/{USER_ID}/events", headers=headers, json=meeting_data)

# Print Response
if response.status_code == 201:
    print("✅ Meeting created successfully!")
    print(response.json())
else:
    print("❌ Failed to create meeting:", response.json())

The event was created successfully, but the attendees did not receive the email. When we checked, it showed: 'Delivery has failed to these recipients or groups: [email protected] Your message wasn’t delivered because the recipient’s email provider rejected it. Remote server returned '550 5.7.708 Service unavailable. Access denied, traffic not accepted from this IP. For more information please go to http://go.microsoft.com/fwlink/?LinkId=526653 AS(7230)

i already enabled the permissions calendars.ReadWrite, OnlineMeetings.ReadWrite but did not send the email

I try that code event is created but mail not get attendees

Upvotes: -1

Views: 45

Answers (1)

Glen Scales
Glen Scales

Reputation: 22032

 'Delivery has failed to these recipients or groups: [email protected] Your message wasn’t delivered because the recipient’s email provider rejected it. Remote server returned '550 5.7.708 Service unavailable. Access denied, traffic not accepted from this IP. For more information please go to http://go.microsoft.com/fwlink/?LinkId=526653 AS(7230)

The issue is nothing to do with the code or Graph its because the destination mail endpoint your trying to send to is rejecting email from the source (your m365 tenant SMTP Mta). If you using a Developer or Trial Tenant this is to be expected because these environments are often exploited by various actors so end up on block lists. If its a production system get you admin to check email flow between the two SMTP endpoints (eg Mailflow https://learn.microsoft.com/en-us/exchange/mail-flow-best-practices/mail-flow-best-practices) in the m365 portal.

Upvotes: 0

Related Questions