Updated 4 months ago

Send Reports via Email Using Graph API – An Essential Method for Secure Report Delivery

by Sudha

10 min read

No Comments

Microsoft 365 reports are a secret weapon, allowing you to monitor the Office 365 environment effectively. To share such reports with your colleagues and users, Outlook has been a helpful collaborative medium. In such a way, to reduce manual effort, you may use the cmdlet “Send-MailMessage,” which has been a popular choice for sending reports via PowerShell. However, there comes a checkpoint!

The Send-MailMessage cmdlet is obsolete. This cmdlet does not guarantee secure connections to SMTP servers. While there is no immediate replacement available in PowerShell, we recommend you do not use Send-MailMessage. For more information, see Platform Compatibility note DE0005.”

Did you ever see the above message? This is a warning note given by Microsoft in its official document, showing that “Send-MailMessage” is less secure😲! Don’t worry! You can start to send reports via email using Microsoft Graph API, which is the most secure method using OAuth tokens, making the O365 environment stand away from security threats

Thus, take a look at this blog to learn how to send reports via email using Graph API.

Choose Microsoft Graph API to Send Reports via Email

Microsoft Graph API acts as a single endpoint, that allows you to access and interact with Microsoft 365 cloud services.

The main reason why it is preferred to use Graph API for report distribution is its “security” 🔐. While sending reports via Graph API, you can reduce the risk of report stealing and other security-related incidents.

Then comes the “efficiency”. Graph API effectively manages the email-sending process, ensuring reports are delivered to the right person at the right time.

Steps to Send Reports via Email Using Graph API

First, you need to configure the steps below to send reports via Graph.

1. Sign-in to Microsoft Graph Explorer: First, sign-in to Microsoft Graph Explorer using your Microsoft 365 account.

2. Configure HTTP Method: In the HTTP request bar, set the HTTP method to “POST“.

3. Set the Endpoint: Next set the HTTP request to any of the two Outlook API calls given below.

  • https://graph.microsoft.com/v1.0/me/sendMail – To send report from the signed-In user.
  • https://graph.microsoft.com/v1.0/users/{UserPrincipalName}/sendMail – To send report from the specified user mailbox, you need to replace the “UserPrincipalName” with the respective user’s email address.

4. Grant Permission: In the “Modify permissions” tab, you can see “Mail.Send” permission. Then, click the “Consent” button to grant the “Mail.Send” permission to the Graph Explorer.

5. Configure content-type: You can set the request body in JSON/MIME formats. So, you can use application/json or text/plain for JSON/MIME objects, based on your requirements. By the way, it is preferred to use JSON format, providing efforts free report delivery.

After configuring the above steps, you can run the given JSON formats to,

Send an Email Message Using Outlook Mail API

You can send an email message to a recipient using the JSON format below by replacing the recipient’s email address. After configuring the respective recipients, click ‘Run query’ to deliver the message.


Note: The above format will be given in default in the response body when you set the “POST /users/{id | userPrincipalName}/sendMail” or “POST /me/sendMail”call. You just need to replace the recipient address in the given format.

Furthermore, if you need to save the message in “Sent Items”, add a “saveToSentItems”: “false” in your JSON object like in the given format.

Email a Report to a Recipient via REST API Call

Sending reports to other admins in Outlook can be made easier and error-free with the use of Microsoft Graph API, which eliminates the need for manual effort. With Graph API, you can include a report by specifying the report name directly in JSON format.

To deliver Microsoft 365 reports with an email message, make use of the JSON format in your Graph.


Note: Once your request is accepted, you will receive a notification with the status “HTTP/1.1 202 Accepted,” indicating that the email sending process has been initiated.

acceptance of HTTP request in Microsoft Graph

In case you don’t find the email in your inbox, check it in your spam folder.

The above JSON format can be helpful to send reports to a small number of recipients. But, when it comes to bulk recipients, you ought to specify the email addresses of all the recipients one by one in the “toRecipients” field, which is a cumbersome task.

However, there is a way to perform bulk operations without logging into Graph Explorer. By integrating Outlook API calls into PowerShell, you can perform bulk report sending operations efficiently.

Use Microsoft Graph API to Send Reports from PowerShell

Graph Explorer may present challenges when dealing with bulk operations, such as sending bulk reports or emailing reports to a large number of people. However, with PowerShell, you can call the Outlook mail APIs to do bulk operations using a registered application.

To achieve this, you must first register an application in Azure AD and generate client secrets for secure access. Also, make sure to note down the client’s secret, as it is not visible later.

Permission: After registering your app in Azure Active Directory, make sure to give “Mail. Send” delegated API permission to your application. To do so, follow the navigation below.

Microsoft Entra admin center> Applications> App registrations> Respective app> Api permissions> Add a permission> Microsoft Graph > Delegated permission> Mail> “Mail.Send” > Add permissions.

Permisison for registers app to send email using Graph api

As you are done with the prerequisites, let’s jump into the important ways below to mail a report using PowerShell and Graph API.

  1. Email a Report to Multiple Recipients Via REST API
  2. Send Multiple Reports to a Recipient via Graph API Call
  3. PowerShell script to Email Bulk Reports to Bulk recipients via Graph

Email a Report to Bulk Recipients Via Microsoft Graph API

Think of a scenario, if you want to share the user activity reports to your co-admins, you have to individually email the reports to them. Wait, instead of manually sending individual reports to different team members, you can use a PowerShell script with a Graph API call, that reads a CSV file containing admins’ email addresses and automatically sends user activity reports to each recipient.

Sample CSV File :

Csv file to send reports to bulk recipients
Now, execute the provided PowerShell script to send reports to multiple email recipients.

The try and catch block in the above script will help you to handle errors that occur due to network issues, invalid input, or server problems.

Email Multiple Reports to a Recipient Via Rest API and PowerShell

Now, think of a vice versa scenario, to send multiple reports to a recipient by calling Outlook mail API, you can use the PowerShell script mentioned below.

To do so, create a CSV file containing the locations of the reports that need to be sent.

Sample CSV File :

send multiple attachments to a recipient
Then, use the PowerShell script mentioned below.

The recipient will receive an email containing multiple reports like the screenshot below.

send multiple reports to a recipients using Graph api

PowerShell Script to Email Bulk Reports to Multiple Recipients via Graph

Sending custom reports to specific users simultaneously via Outlook can be challenging. But PowerShell script with API call can make it easy by sending multiple reports to bulk recipients at a time.

Thus, create a CSV file showing the recipient address and corresponding attachments’ path.

Sample CSV File :

send bulk attachments to bulk recipients

You can then use the PowerShell script given below to email multiple reports to bulk recipients.

Also, you can schedule PowerShell scripts with Task scheduler, allowing you to send reports to the intended recipients at specific intervals.

Furthermore, you can access the Microsoft Graph activity logs to analyze API requests originating from the Graph Explorer, PowerShell, applications, and more.

Hassle-free Rapid Report Delivery with AdminDroid

If you are a newbie to PowerShell, Graph Explorer, or Task Scheduler, then executing the above scripts and queries might pose challenges. Leave those methods behind! Because AdminDroid effortlessly manages all the report-sending tasks, providing a unified solution for your needs.

With AdminDroid, you can experience the benefit of real-time report emailing, ensuring immediate delivery to users without any delays.

By the way, native tools lack the ability to save reports in your desired format, scheduling of reports, and more. However, AdminDroid bridges this gap with its Advanced Scheduling feature. It’s robust scheduling feature allows you to effortlessly send reports to recipients at specific intervals, eliminating the need for manual script execution and queries at each interval.

Some of the key benefits of scheduling reports with AdminDroid:

  1. Despite managing multiple tenants, AdminDroid offers a convenient way to select the desired tenants for scheduling reports.
  2. You can customize the body, attachment type, and subject of your email.
  3. The Scheduled reports can be saved as PDF, HTML, CSV, XLS, XLSX, and RAW formats.
  4. You can set up schedules on a daily, weekly, or monthly basis, and if needed, you can also utilize the recent schedule time for your report delivery.
  5. You can permit other admins to subscribe to your schedules, allowing them to receive the scheduled reports in addition to the specified recipients.
  6. You have the flexibility to store scheduled reports either on the local disk or a remote share.

Schedule Reports - AdminDroid Office 365 Reporter

Furthermore, monitoring email flows constantly can protect you against security risks. So, you can schedule Exchange Online mail protection reports for constant monitoring of spam and malware mail, ensuring a protected Exchange Online environment.

Added to the above, you can schedule email traffic reports with AdminDroid and stay compliant by periodically reviewing inbound and outbound email traffic in your Office 365.

Also, to grasp email activities at first sight, AdminDroid offers a email analytics dashboard for following top malware and phishing emails in your Exchange Online.

email dashboard in AdminDroid

Monitor Microsoft 365 email activities and mitigate threats with AdminDroid!

Don’t wait for email attacks to strike unexpectedly! Act now and download AdminDroid to safeguard your Exchange Online environment.

As a wrap-up, consider using Microsoft Graph API calls as a safe and effortless way to send M365 reports via email. Hope you gain enough information about a way to send reports via email using Graph API. Don’t hesitate to raise your doubts in the comments section. We are always ready to resolve it!

Share article