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:
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.