Currently using Microsoft Graph, wanted to know whether a mail is soft bounced or not

sarath 120 Reputation points
2023-10-20T06:00:54.71+00:00

Hi Team,

Here is endpoint in Question : https://learn.microsoft.com/en-us/graph/api/message-get?view=graph-rest-1.0&tabs=http

How do I know whether a message, which we fetch via the get message endpoint above, is indicating a soft bounce or not?

Currently even if we fetch the MIME content, its not giving any data about soft bounce

Please let us know

Outlook
Outlook
A family of Microsoft email and calendar products.
3,138 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,900 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 38,031 Reputation points
    2023-10-20T10:11:38.1+00:00

    Hi @sarath

    There is no way to check if a message is a soft bounce with a simple API call. You need to use graph SDK to make some logical judgments.

    Please refer to the following steps:

    • Call the /messages endpoint with the id of the mail you want to check.
    • In the response, look for the internetMessageHeaders property, which contains an array of key-value pairs that represent the email headers.
    • Loop through the internetMessageHeaders array and look for the header named "X-Microsoft-Antispam-Mailbox-Delivery".
    • The value of this header contains a string that indicates the delivery status of the mail. For example, if the value is "noattr:0", it means that the mail was delivered successfully. If the value is "noattr:1", it means that the mail was soft bounced.
    • A soft bounce occurs when the mail is temporarily rejected by the recipient's server due to reasons such as mailbox full, server down, or rate limit exceeded. A hard bounce occurs when the mail is permanently rejected by the recipient's server due to reasons such as invalid address, domain not found, or blocked sender.
    • You can also look for other headers that indicate the reason for the bounce, such as "X-Forefront-Antispam-Report" or "X-Microsoft-Exchange-Diagnostics".

    Here is an example of a C# code snippet that uses Microsoft Graph SDK to check whether a mail is soft bounced or not:

    var message = await graphClient.Users["{user id}"].Messages["{message id}"].GetAsync((requestConfiguration) =>
    {
        requestConfiguration.QueryParameters.Select = new string[] { "internetMessageHeaders" };
    });
    
    bool isSoftBounced = false;
    string bounceReason = "";
    
    foreach (var header in message.InternetMessageHeaders)
    {
        if (header.Name == "X-Microsoft-Antispam-Mailbox-Delivery")
        {
            if (header.Value.Contains("noattr:1"))
            {
                isSoftBounced = true;
            }
        }
        else if (header.Name == "X-Forefront-Antispam-Report" || header.Name == "X-Microsoft-Exchange-Diagnostics")
        {
            bounceReason = header.Value;
        }
    }
    
    if (isSoftBounced)
    {
        Console.WriteLine("The mail was soft bounced.");
        Console.WriteLine("The reason for the bounce was: " + bounceReason);
    }
    else
    {
        Console.WriteLine("The mail was not soft bounced.");
    }
    

    Test:

    User's image

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.