How to create a new instance of MapiAttachment

Hi,

I am trying to create a new attachment from a string input and add it to an existing MapiMessage in a PST file.
I do not see any constructors for MapiAttachment class.
Why is it so?
How can I add a new attachment to an existing message accessed as a MapiMessage using pst.ExtractMessage(…)?

@Srinidhi,

You can add an attachment to MapiMessage using the following method MapiAttachmentCollection.Add(MapiAttachmentCollection.Add | Aspose.Email for .NET API Reference):

// Add plain text attachment
mapiMessage.Attachments.Add("MyAttach.txt", Encoding.UTF8.GetBytes("This is content of palin text attachment"));

// Add attachment from pdf file
mapiMessage.Attachments.Add("document.pdf", File.ReadAllBytes(@"D:\SomePdfFile.pdf"));

Hi @margarita.samodurova,

Thanks for the quick response.
I’m trying to set ContentLocation on a MapiAttachment object as follows

attach.SetProperty(
            new MapiProperty(
                0x3713 // Content Location
            ).Descriptor,
            <uri>
        ); 

But I am getting AsposeNotSupportedException, is contentLocation not supported for mapi attachments?

Thanks,

Hi @margarita.samodurova,

Another question, probably a bug,
I’m getting null when I try to access the ItemId of the MapiAttachment.
Sample code:

mapiMessage.Attachments.Add("MyAttach.txt", Encoding.UTF8.GetBytes("This is content of palin text attachment"));
var mapiAttachment = mapiMessage.Attachments.Last<MapiAttachment>();
// Is null
Console.WriteLine(mapiAttachment.ItemId)

Could you please help resolve this?
Thanks,
Srinidhi

Hi @margarita.samodurova,

Another question, how to add an attachment to an existing message in a pst store.
Given a situation where I have the entry id of a message, I can extract the message using ExtractMessage method on the PersonalStorage object. But this seems to return only a copy of the message but not a reference to the message in the PersonalStorage object.

This way any attachment added through mapiMessage.Attachments.Add(...) do not make any change on the PST file.

How do I add an attachment to an existing message in the PST file?

I see FolderInfo.UpdateMessage(entryIdString, MapiMessage) as an option, but this does not update the attachments list. Looks like only the properties are getting updated, but not the attachment list.

TIA,
Srinidhi

@Srinidhi,

Your request requires some time for investigation. You will get the answer asap.
Thanks for waiting.

@Srinidhi,

Your request requires some time for investigation. You will get the answer asap.
Thanks for waiting.

  1. There must be a data type part in the tag. For example, 0x3713001f.
    But the preferable way to set properties is using KnownPropertyList:
att.SetProperty(KnownPropertyList.AttachContentLocation, <uri>);
  1. ItemId is used for the attachment identification on the server side. If you’ve created the attachment locally, it doesn’t have ItemId. Can you, please, specify what you wanted to use this property for?
  1. yes, this method is used to update a message properties. Updating attachments is a more complicated process. For updating messages with attachments there’s only one way so far:

Note: after adding the updated message, it will have a different EntryID.

Hi @margarita.samodurova,

Thanks for the clarification on this.
Is it in your roadmap to support adding attachments to MAPI messages from the PST store?

Hello @Srinidhi,

This feature hasn’t been planned yet, as it requires preliminary investigation to define if it is possible to implement.

@Srinidhi
We’ve created an investigation ticket on this feature.

Issue ID(s): EMAILNET-41003

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.