We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

HTML body is converted to plain text

Hi, I'm using the Aspose.Email class to convert incoming emails to a SharePoint document library to MSG format and for some reason the body of themails are being converted to pain text (ugly signatures).

The SharePoint event supplies a stream for the incoming email that I read into an EML file (MailMessage) then generate an MSG file using the EML and save the MSG out to a file in the library.

My problem is that emails sent to the library from external accounts, like Gmail, survive the conversion process while email sent from (Outlook) accounts on the same domain as the SharePoint server have their HTML bodies converted to plain text.

Here is the code I'm using:

public override void EmailReceived(SPList list, SPEmailMessage emailMessage, String receiverData)

{

MemoryStream MSGmemoryStream;

MemoryStream MSGstream;

Stream RawStream = emailMessage.GetMessageStream();

MailMessage EMLMessage = MailMessage.Load(RawStream, MessageFormat.Eml);

EMLMessage.Save(MSGmemoryStream, MailMessageSaveType.OutlookMessageFormatUnicode);

MapiMessage MSGMessage = MapiMessage.FromStream(MSGmemoryStream);

MSGMessage.Save(MSGstream);

SPFile fl = list.RootFolder.Files.Add(destinationList.RootFolder.ServerRelativeUrl + "/" + filename, MSGstream, true);

SPListItem NewEmailItem = fl.Item;

}<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I don't know why this code works fine for some emails and not for others. I can't find any way of distiguishing between an email sent from gmail / hotmail / yahoo and one sent from and Outlook client. As this is the only difference I am assuming it has something to do with the program that sends the email in the first place.

Thanks, Peter.

Hi Peter,


Please accept my apologies for the delayed response.

To investigate your issue and raise a ticket, please provide us the following information,
  • What version of Aspose.Email for SharePoint are you using?
  • OS (Windows Version)
  • Architecture (32 / 64 bit)
  • Service Packs
  • Any other information that you like to share regarding your testing environment.

Also I would suggest you to save both MemoryStream objects from your source code to separate MSG files and share them here (in an archive) for our review.

Thanks and Regards,
  • Aspose.Email for .NET 3.5
  • File version: 1.5.0.0
  • Product version: 2012.2.22
  • Windows Server 2008 R2 x64 SP1
  • SharePoint 2010 version: 14.0.4763.1000 (english)
  • Outlook 2010 x32
  • Exchange 2010

I have tryed sending an email from a Windows Server 2008 R2 x64 workstation and a Windows 7 x64 workstation both using Outlook x32 and had the same result.

The incoming stream has a property for the body with HTML formatting/tags. Is there a way of forcing the mailmessage (EML) file to have an HTML formatted body and to copy the HTML from the incoming stream? As this is the step where the HTML is "lost", according to my debugging.

Thanks, Peter.

My appologies Babar, further testing shows that this is only happening in one library. I have taken a template of the library and used it in an attempt to reproduce the error but it works fine.

Something must have happened to my test library while I was developing the event receiver.

My sincerest apologies for wasting your time.

Peter.

Hi Peter,


Thank you for sharing your analysis. Please feel free to write back in case of further questions or comments.

Regards,