question

ExUser44-0578 avatar image
0 Votes"
ExUser44-0578 asked ExUser44-0578 answered

Changes to certain mail properties not retained when sending a mail from Exchange online to Exchange On-premises using Outlook interop API (.NET)

Hi Team,

We have an archival solution that where MS Exchange is source. As part of this, we have an Outlook Add-in for achieving certain use cases like user defined archival. One particular functionality of this Add-in is a send a mail. Please find below pseudo-code for the same. This functionality works fine with Outlook in an Exchange On-Premises environment, and even works well in Exchange Online environment. Now, as we are planning to support Exchange Hybrid, we see that when the mail is sent from an Online Mailbox to an On-premises mailbox, some of the properties namely, the message class and the custom properties required by our application, are not retained. This is only seen when sending from Online to On-Premise, it works fine in case of sending a mail from On-Premise to On-Premise or Ex Online to Ex Online.

 using Outlook = Microsoft.Office.Interop.Outlook;    
 public void sendMail(Outlook.Application a)
         {
             Outlook.MailItem theMail = null; /       
             try
             {
                 theMail = (Outlook.MailItem)a.CreateItem(Outlook.OlItemType.olMailItem);
                 theMail.MessageClass = "CustomMessageClass";    // Changes not retained
                 theMail.To = recepient;
                 theMail.Subject = "The Subject";
                 //Code to set custom MAPI properties - Changes not retained
                 theMail.DeleteAfterSubmit = true;
                ((Outlook._MailItem)theMail).Send();
             }
             catch (Exception ex)
             {
                 // Log Exception
             }
             finally
             {
                 // Free Resources
             }
         }
office-vba-devoffice-addins-dev
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Adding right tags/teams to assist

0 Votes 0 ·

Hi! Has anyone got a chance to look at the above issue? Or has any pointers/suggestions?

Any help would be greatly appreciated. Thanks!

0 Votes 0 ·
Deva-MSFT avatar image
0 Votes"
Deva-MSFT answered

Once it hit the .send() then API pushes the message for mail delivery and its journey ends there. So you need to track/trace between on-prem/EXO. I would try this:
- Work with admin and enable tracing/mail flow at your Exchange onprem/EXO to see how the mail goes out/received, whether it contains the mail property or not
- Validate the above message properties using tool like MFCMAPI or EWSEditor and see what we notice in the EXO & Exchange onprem
- If nothing works, i would suggest you to save the message and then send it to see if it makes any difference.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ExUser44-0578 avatar image
0 Votes"
ExUser44-0578 answered

@Deva-MSFT , Thanks for your answer! Below are our responses to your suggestions. We would be happy to hear any follow-up points/suggestions etc..

Work with admin and enable tracing/mail flow at your Exchange onprem/EXO to see how the mail goes out/received, whether it contains the mail property or not

We are working on checking on this.


Validate the above message properties using tool like MFCMAPI or EWSEditor and see what we notice in the EXO & Exchange onprem

We have verified using MFCMAPI that the custom properties and the message class changes are not retained when mail travels from online to on-prem . The custom properties are not at all present where as the message class contains the default value "IPM.Note".
However, when the mail is sent from on-prem to on-prem OR online to online, the custom properties are present as well as the message class property contains the desired value. This was also verified using MFCMAPI.


If nothing works, i would suggest you to save the message and then send it to see if it makes any difference.

As per our design, we need the DeleteAfterSubmit = true property as the mail sent should not be retained in the senders mailbox. The MS docs says DeleteAfterSubmit is "True if a copy of the mail message is not saved upon being sent"

Thanks!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.