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,
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,
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);
Could you send us an msg file example before editing in the outlook and after editing?
Thanks.
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
ok thanks i will wait
I was not able to reproduce the issue you described.
I have performed the following steps:
- 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);
-
Open saved
fetched.msg
in Outlook, change its body and save it asmodified.msg
. -
Load
modified.msg
into MailMessage and added it to the server.
var modifiedMsg = MailMessage.Load("modified.msg");
imapClient.AppendMessage(modifiedMsg);
- 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
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
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