Difference MailMessage and MapiMessage

Hi,

I am evaluating your Email product since we are looking for a solution for working with MSG-files in our Java application.

I noticed that there are two classes available for working with MSG-files, these being MailMessage and MapiMessage. Which one should be used? On first sight I cannot really make a distinction between the two since they both seem to support reading in MSG-files and creating MSG-files. According to the documentation MapiMessage only works with MSG-files where as MailMessage also works with EML-files for example. Is MailMessage maybe more limited compared to MapiMessage when working with MSG-files?

Thanks in advance!

Kind regards,
Yannick

Hi Yannick,


Thank you for writing to Aspose suppor team.

You have got the right difference between the two i.e. MailMessage has additional capability to process EML and MHT files as well, while the MapiMessage class can deal with MSG files only. However, MapiMessage can be used to load an EML file that is already loaded in MailMessage using the MapiMessage.FromMailMessage method. Following are some of the features that are supported by MapiMessage only:

1. MailMessage doesn’t give you access to the Message property stores which is only available in MapiMessage. You can have a look at our article Accessing Outlook Mapi Properties for this purpose.

2. MapiMessage can be used to load MSG files directly and add them to PST. MailMessage objects can not be added directly to a PST as these need to be converted to MapiMessage first.

3. Other outlook items such as Contacts, Tasks, Distribution lists and Notes are also dealt by MapiMessage only.

Please feel free to write to us in case you have any additional query/inquiry in this respect.

1 Like

Hi Kashif,

Thanks for your reply!

This certainly clarifies a lot. I noticed #1 as well since when I converted a MailMessage to MapiMessage and saved it to a file the file had its size reduced.

Hi Yannick,


Reduction in size doesn’t related to any loss of data or other such activity as some fields are compressed during the conversion. Neither this has any impact on the data display in Outlook as well. Please let us know if you have any further query/inquiry related to Aspose.Email. We’ll be glad to assist you further.

I saved an email in .msg format like this

**MailMessage message = client.FetchMessage(info.UniqueId);**
**string fileMessage = Path.Combine(folder, info.UniqueId + "_MailMessage.msg");**

**MapiMessage mapiMessage = MapiMessage.FromMailMessage(message);**
**mapiMessage.Save(fileMessage);**

I edited the _MailMessage.msg file in outlook and when sending or storing
with imap the file sends without change

[CODIGO]
MsgLoadOptions msgLoadOptions = new MsgLoadOptions();
MessageFormat messageFormat = msgLoadOptions.MessageFormat;
msgLoadOptions.PreserveEmbeddedMessageFormat = false;

MailMessage messageLoad = MailMessage.Load(fileMessage, msgLoadOptions);
messageLoad.Date = DateTime.Now;

client.SelectFolder(ImapFolderInfo.InBox);
string uid = client.AppendMessage(messageLoad);
[/CODE]

does not work, the .msg file sends without changes

Hello, @gsudariojr

I edited the _MailMessage.msg file in outlook and when sending or storing
with imap the file sends without change

Did you save the changes before sending the message?
Thanks.

I’m editing the .msg file in Outlook, it’s not creating the email with the changes

I noticed that the htmlbody and htmltext properties do not change, the body property changes, but when sending the email the change is not sent

MailMessage mailMessage = client.FetchMessage(info.UniqueId);
MapiMessage mailOutlookMapiMessage = MapiMessage.FromMailMessage(mailMessage);
                        mailOutlookMapiMessage.SetMessageFlags(MapiMessageFlags.MSGFLAG_UNSENT);
mailOutlookMapiMessage.Save(fileMessage);

MailConversionOptions mailConversionOptions = new MailConversionOptions();
mailConversionOptions.PreserveEmbeddedMessageFormat = false;

MapiMessage MapiMessageAlterado = MapiMessage.FromFile(fileMessage);
MailMessage mailMessageAlterado = MapiMessageAlterado.ToMailMessage(mailConversionOptions);

client.SelectFolder(ImapFolderInfo.InBox);
string uid = client.AppendMessage(mailMessage);

@gsudariojr

Could you send us an msg file example before editing in the outlook and after editing?

Thanks.

mailmessage_from_file_edited_in_outlook.png (22.5 KB)
messages.zip (28.4 KB)

@gsudariojr

Your code is incorrect: you are adding the original message instead of edited message.

Instead of:

string uid = client.AppendMessage(mailMessage);

use

string uid = client.AppendMessage(mailMessageAlterado);

Thanks.

It doesn't work, could you send me an example code?

Sorry, the code was a mess, I reformulated the code to make it easier for you to understand, and I ended up forgetting to change the variable

@gsudariojr

We’ll check it out and get back to you a bit later.

Thanks.

ok thanks i will wait

@gsudariojr

I was not able to reproduce the issue you described.
I have performed the following steps:

  1. Fetch an eml from the server and save it in MSG format.
var eml = imapClient.FetchMessage(info.UniqueId);
eml.IsDraft = true;
eml.Save("fetched.msg", SaveOptions.DefaultMsg);
  1. Open saved fetched.msg in Outlook, change its body and save it as modified.msg.

  2. Load modified.msg into MailMessage and added it to the server.

var modifiedMsg = MailMessage.Load("modified.msg");
imapClient.AppendMessage(modifiedMsg);
  1. Open Outlook connected to the Imap server and made sure the message with the changed body was added.

Note, you can only append the modified message to the Imap server. There are no IMAP commands for editing of an existing message.

Thanks.

because you need to use the “save as” option, is there another faster way? without overwriting the .msg file

@gsudariojr

Sorry, I do not understand what you mean, please specify. Thanks.

every time you change the .msg file via outlook do you have to use the “save as” option? When I just click on “Save” it doesn’t work, the .msg file is not changed

@gsudariojr

There is no difference using save or save as.
Try this:

if (!File.Exists("fetched.msg"))
{
    var eml = imapClient.FetchMessage(info.UniqueId);
    eml.IsDraft = true;
    eml.Save("fetched.msg", SaveOptions.DefaultMsg);
}
else
{
    var modifiedMsg = MailMessage.Load("fetched.msg");
    imapClient.AppendMessage(modifiedMsg);
}

I can’t understand, the changes are only effective when I use the “save as” option and overwrite the .msg file

@gsudariojr

I’ll check it out on my side.