Converting email to document

Hi,

I’m trying to convert an email to a word document, and I’m encountering the problem that the background of the email is not included in the document.

I’m using the following code:

// the MailMessage class is part of Aspose.Network
private Document GetDocumentFromEmail(MailMessage mailMessage)
{
    // create the Word Document
    Document document = new Document();

    // create the Word DocumentBuilder
    DocumentBuilder documentBuilder = new DocumentBuilder(document);

    // set the papersize to A4
    documentBuilder.PageSetup.PaperSize = PaperSize.A4;

    if (mailMessage.IsBodyHtml && !string.IsNullOrEmpty(mailMessage.HtmlBody))
    {
        documentBuilder.InsertHtml(mailMessage.HtmlBody);
    }
    else
    {
        documentBuilder.Write(mailMessage.TextBody);
    }

    return document;
}

Can someone please tell me what I’m doing wrong?
Attached is a test email file.

Sincerely,

Geert-Jan Smulders

Hello
Thanks for your request. If you try to save _message.HtmlBody as separate HTML file and open this HTML document using any browser, you will see, there is no any background. After inserting this HTML inside a Document, you will see the same result.
Best regards,

Hi Andrey,

Thanks for your reply. I was out of town for a week, so I couldn’t comment.

In the html code it says the body element has an attribute called background:
background=“cid:220A7C3D-E10C-497D-BC2F-6F63EF93E4E2”

This points to a linked resource of the MailMessage.
Is it possible to extract the linked resource and insert is as the background of the document?

Sincerely,

Geert-Jan Smulders

Hello
Thanks for your request. If you have an ability to get this background using Aspose.Network then you will be able to set this background using BackgroundShape property of Aspose.Words document object. Please see the following link:
https://reference.aspose.com/words/net/aspose.words/documentbase/backgroundshape/
Best regards,