Free Support Forum - aspose.com

Message unreadable when using license - saving msg files to O365 mailbox

I’m using ASPose.Email to read msg files from file system and EMS managed API to store the messages to O365 group mailbox.
When using evaluation copy the message text is shown perfectly (with evaluation text) but when adding the license the text of the message is just showing “Your message can’t be displayed right now”

The mail metadata (To, subject, preview of body) looks perfect, but mail body when selecting the mail cannot be rendered.

Screenshot 2021-05-25 082545.png (71.1 KB)

@henrikn,
Welcome to our community! Thank you for the issue description. To investigate this case, please share and specify the following:

  • the code example reproducing the problem
  • the MSG file
  • the version of Aspose.Email you used
  • the email software to view the message

But first, please check the issue with the latest version of Aspose.Email (C#, Java).

Hi Andrey

The core piece is this:

using (var message = Aspose.Email.MailMessage.Load(file))
{

EmailMessage email = new EmailMessage(service);
MemoryStream stream = new MemoryStream();

message.Save(stream);
byte[] byteresult = stream.ToArray();
email.MimeContentUTF8 = new MimeContentUTF8(byteresult);

ExtendedPropertyDefinition PR_MESSAGE_FLAGS_msgflag_read = new ExtendedPropertyDefinition(3591, MapiPropertyType.Integer);
email.SetExtendedProperty(PR_MESSAGE_FLAGS_msgflag_read, 1);
email.Save(SpamInbox);
}

it takes a full path to a msg file (file) and takes the byte stream and load into the EWS message (email) using the MimeContentUTF8 property.

it then saves the message to the inbox (SpamInbox) using the EWS managed API.

The inbox is a O365 Group mailbox and this is the code used to access the EWS part:

string username = “USERNAME”;
string pw = “PASSWORD”;
string alias = “ALIAS FOR MAILBOX”;

var exchangeServer = “https://outlook.office365.com/EWS/Exchange.asmx”;
ExchangeService service = new ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2016);

service.Url = new Uri(exchangeServer);
service.Credentials = new WebCredentials(username, pw);
service.TraceEnabled = false;

// Get the mailbox
Mailbox SpamMailbox = new Mailbox(alias);
FolderId SpamInbox = new FolderId(WellKnownFolderName.Inbox, SpamMailbox);

Folder inbox = Folder.Bind(service, SpamInbox);

The user (USERNAME) must have a mailbox in O365.

we are using: using Microsoft.Exchange.WebServices.Data; for EWS available in a nuget:

and version 21.4.0 of Aspose.Email

I’m using Outlook for the web to read mails.

One msg file attached

(Attachment SV Coachingsamtaler - opgavekontrakt 2014-07-29T110438.3338099.msg is missing)

trying as zip

SV Coachingsamtaler - opgavekontrakt 2014-07-29T110438.3338099.zip (51.1 KB)

@henrikn,
Thank you for the additional information. I logged the issue in our tracking system with ID EMAILNET-40239. Our development team will investigate this case. I will inform you about any progress.

@henrikn,
Our development team investigated the issue. Unfortunately, we cannot reproduce the issue on our side. Could you share test credentials for us, please?

But first, please set Base64 encoding in the TransferEncoding property for text/plain body as below and check the problem again:

using (var message = Aspose.Email.MailMessage.Load(file))
{
    EmailMessage email = new EmailMessage(service);
    MemoryStream stream = new MemoryStream();
    message.AlternateViews[0].TransferEncoding = Aspose.Email.Mime.TransferEncoding.Base64;
    message.Save(stream);
    byte[] byteresult = stream.ToArray();
    email.MimeContentUTF8 = new MimeContentUTF8(byteresult);

    ExtendedPropertyDefinition PR_MESSAGE_FLAGS_msgflag_read = new ExtendedPropertyDefinition(3591, MapiPropertyType.Integer);
    email.SetExtendedProperty(PR_MESSAGE_FLAGS_msgflag_read, 1);
    email.Save(SpamInbox);
}

Also, try to use the Aspose EWSClient class as below:

var credentials = new NetworkCredential("test@xxxxx.onmicrosoft.com", "password");
var client =  EWSClient.GetEWSClient("https://outlook.office365.com/EWS/Exchange.asmx", credentials);
var message = Aspose.Email.MailMessage.Load(msgFilePath);
client.AppendMessage("Inbox", message);

Documents: Working with Exchange EWS Client
API Reference: EWSClient Class

In the latter example - I guess it just goes for the user mailbox - how do you specify an alternate group mailbox?
The user mailbox is not in use here - only the group mailbox - hence the user must be exchange admin to be able to save messages across group mailboxes - and sorry - I cannot share credentials!

@henrikn,
It will take me a while to clarify this point. I will let you know as soon as possible.

@henrikn,
Have you checked the issue with changes as shown in the first code example?

@Andrey_Potapov

I checked the code against a different tenant and could not reproduce either so we are currently tracing why the customer tenant is error-prone!
But also - why it works when running without the license? Apart from adding some text to body etc. - do you manipulate the encoding/mine type in any way?

@henrikn,

If the issue persists, we need some additional information to reproduce and investigate it further.

Aspose.Email can work differently with and without a license. For example, please take a look at Evaluation Version Limitations. We have to investigate the issue if there is a bug.