Setting AttachContentId on a MapiAttachment hides it outlook

Hi,

I am trying to create an inline image attachment in a MapiMessage object and then store it in a PST file.

When I set the AttachContentId property on a MapiAttachment object, the attachment is not visible either inline or the attachments pane in outlook client (on mac).
I’ve verified that setting the AttachmentHidden property to true does not help.

Could you please share all the required properties to be set for an inline attachment added as a mapi attachment to a mapi message added to a PST file?

@Srinidhi,

Can you, please, send us the full code sample, that you use, to add an inline attachment to the message?

Thank you.

@margarita.samodurova,
Please find the sample code:

var msg = MapiMessage.FromMailMessage(
    <mail message object>,
    MapiConversionOptions.UnicodeFormat
);
msg.Attachments.Add("test.png", <A byte array from the image>);
var attach = msg.Attachments.Last<MapiAttachment>();
            attach.SetProperty(
                KnownPropertyList.AttachContentId,
                "some-content-id"
            );

            attach.SetProperty(
                KnownPropertyList.AttachMimeTag,
                "image/png"
            );

            attach.SetProperty(
                KnownPropertyList.LastModificationTime,
                DateTime.Now()
            );

            attach.SetProperty(
                KnownPropertyList.AttachmentHidden,
                true // setting to either true or false doesn't work
            );
     
        // https://docs.aspose.com/email/java/differentiate-between-inline-and-regular-attachments/
            attach.SetProperty(
                KnownPropertyList.AttachFlags,
                0x00000004
            );

            attach.SetProperty(
                new MapiProperty(
                    0x3716001E // Even tried 0x3716001F
                ).Descriptor,
                "inline"
            );

The content id set in property AttachContentId is used in the message body with bodyContentType being BodyContentType.Html.
Setting the AttachContentId has two effects:

  1. The image attachment is not shown on the preview pane of the message on the outlook client.
  2. The image is not embedded inline in the message.

I’m not sure what else needs to be set to mark the attachment as inline and make it available as part of the message body.

Note:

  1. Setting AttachContentId on any image attachment (even if it’s not inline) hides the attachment from the attachment preview pane in outlook client.
    Screen Shot 2023-03-21 at 8.39.10 PM.jpg (175.0 KB)

  2. Removing the extension (.png in this case) makes the attachment appear on the attachment preview pane in outlook client but it appears as a text file even when the AttachMimeTag is set.
    Screenshot 2023-03-23 at 10.19.30 AM.jpg (244.3 KB)

@Srinidhi,

Please try the following code to create a message with inline attachment:

// create message and set html body 
MapiMessage msg = new MapiMessage("from@from.com","to@to.com", "Test message", ""); 
msg.SetBodyContent(@"<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 
<h1>Test with image</h1> 
<img src=""cid:attach1234""> 
<p>Test with image</p> 
</body> 
</html>", BodyContentType.Html); 
// add some image from file as inline 
attachment msg.Attachments.Add("image.jpg", File.ReadAllBytes(@"D:\image.jpg")); 
msg.Attachments[0].SetProperty(KnownPropertyList.AttachContentId, "attach1234"); 
msg.Attachments[0].SetProperty(KnownPropertyList.AttachmentHidden, true); 
// save message 
msg.Save(@"D:\test1.msg"); 

Hi @margarita.samodurova,

This fails (PFA the Screenshot for the above code executed to create a PST file).
Please help resolve this asap.

Thanks,
Srinidhi

Hello @Srinidhi,

I’m sorry, but we can not see the screenshot.

Can you, please, provide more details on the problem?

Hi @margarita.samodurova,

Oh sorry, I forgot to upload the screenshot. PFA.
The issue is that the inline attachment, is not being displayed in the outlook client as an image, but just as [cid:attach1234] (Based on the example you posted).

Screenshot 2023-04-17 at 2.22.22 PM.jpg (114.8 KB)

@Srinidhi,

In the attached file MsgToPst.zip (96.6 KB)
you can find the project of a sample application that creates a message containing an inline image in the body and adds such a message to pst.

All you have to do is:

  • unzip the file

  • open and run the project in visual studio

  • open the pst file from the output folder in the project root in Outlook and make sure that the message is displayed with the image.

We’ll be happy to see your feedback.

Hi @margarita.samodurova,

I still see the same issue.
Screenshot 2023-04-18 at 9.29.19 AM.jpg (242.1 KB)

Observations:

  1. When KnownPropertyList.AttachContentId is set, the attachment is neither displayed at the top in the attachments preview pane or inline. But there is some indication that the attachment exists (Notice the clip icon above the time in the email list on the left of the screenshot above).

  2. When I don’t set the KnownPropertyList.AttachContentId property, the attachment is shown in the attachment preview but not as inline attachment (Screenshot 2023-04-18 at 9.34.04 AM.jpg (203.6 KB)
    )

  3. Setting the KnownPropertyList.AttachmentHidden property does not make a difference in either case.

Please let me know if we can have a call for this discussion.
It would be very helpful to get this resolved asap.

Thanks,
Srinidhi

@Srinidhi,

I’ve got some questions:

  • Do you use Outlook for Mac?
  • Can you, please, specify the steps you make when opening PST file there?
  • Try to open the attached PST file My Outlook Data File.zip (35.1 KB)
    and check if the image is displayed in the message.

Hi @margarita.samodurova,

  1. Yes. I’m using Outlook for Mac.
  2. In Outlook app, File -> Import… -> Select the PST file to import.
  3. It does! The image is display in the message.
    Is there something specific that needs to be set for this?

Thanks,
Srinidhi

Hello @Srinidhi,

We have opened the following new investigation ticket in our internal issue tracking system: EMAILNET-41035

Hi @margarita.samodurova,

Could you please let me know the exact issue?

Thanks,
Srinidhi

@Srinidhi,

As you have been informed recently, we have created an investigation ticket on your issue. As soon as the problem is solved, we will provide you with detailed comments and a possible solution.

We are sorry to keep you waiting. Thanks for your understanding and patience.

Hi @margarita.samodurova,

Any update on this?

Hi @margarita.samodurova,

Does this also address the issue of HTML itself not being rendered correctly?
Any of the styling was also not rendered properly on the Outlook for Mac app.
Please let me know what is the issue and the expected time for the fixes.

Thanks,
Srinidhi

The investigation of your issue is still in progress. We’re facing the difficulty to reproduce it in environment similar to yours. It works with Windows just fine.

Thank you for your patience.

Sure.
Do you mean the same PST opened in an outlook app on windows works fine?

@Srinidhi,

That’s right. The same PST file opened in Outlook on Windows works fine.

@Srinidhi

If you want to open the message properly on MAC you need to use the compress option with body content:

// create message and set html body 
MapiMessage msg = new MapiMessage("from@from.com","to@to.com", "Test message", ""); 
msg.SetBodyContent(@"<!DOCTYPE html> 
<html> 
<head> 
</head> 
<body> 
<h1>Test with image</h1> 
<img src=""cid:attach1234""> 
<p>Test with image</p> 
</body> 
</html>", BodyContentType.Html, true); //<<
// compression(true) - Specify that the content should be compressed.