Spire.Email for .NET is a professional .NET Email library specially designed for developers to create, read and manipulate emails from any .NET (C#, VB.NET, ASP.NET) platform with fast and high quality performance.

Fri Oct 19, 2018 9:54 am

I would like to know if there is anyway we can convert an email to an image.

I understand that you can convert the email to a MHTML file.

I am aware that is it not possible to do so directly as there is no such function for spire email, perhaps we can do it something like email => MHTML = >image or email > html => image.

Please advise or suggestion alternative.
thanks

vernon1111
 
Posts: 44
Joined: Fri Mar 02, 2018 4:34 am

Fri Oct 19, 2018 10:44 am

Dear Vernon,

Thanks for your inquiry.
Yes, there is no directly method to do the conversion from email to image. You could extract the text from email first.
Extract message contents

Then convert the text to image, both Spire.Doc and Spire.PDF support the function.
Spire.Doc:
Code: Select all
Document doc = new Document();
doc.LoadText("ExtractMessageContents.txt");
Image image = doc.SaveToImages(0, ImageType.Bitmap);
image.Save("result.png", ImageFormat.Png);

Spire.PDF:
Code: Select all
string text = File.ReadAllText("ExtractMessageContents.txt");
PdfDocument doc = new PdfDocument();
PdfSection section = doc.Sections.Add();
PdfPageBase page = section.Pages.Add();
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 11);
PdfStringFormat format = new PdfStringFormat();
format.LineSpacing = 20f;
PdfBrush brush = PdfBrushes.Black;
PdfTextWidget textWidget = new PdfTextWidget(text, font, brush);
float y = 0;
PdfTextLayout textLayout = new PdfTextLayout();
textLayout.Break = PdfLayoutBreakType.FitPage;
textLayout.Layout = PdfLayoutType.Paginate;
RectangleF bounds = new RectangleF(new PointF(0, y), page.Canvas.ClientSize);
textWidget.StringFormat = format;
textWidget.Draw(page, bounds, textLayout);
doc.SaveAsImage(0).Save("result2.png");

Please download our Spire.Office Platinum (DLL Only) Version:3.10.2 and have a try.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Sat Oct 20, 2018 3:15 am

Hi Nina,

Thanks for the suggestion.

Is there anyway we can generate the image with the original styling from the mailbody and inline images?

vernon1111
 
Posts: 44
Joined: Fri Mar 02, 2018 4:34 am

Mon Oct 22, 2018 2:26 am

Hi,

Thanks for your feedback.
Sorry there is no suitable method to achieve your demand at present. We will consider adding a new feature to make it available. If it is achievable in the future, we will inform you.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Fri Jul 26, 2019 6:03 am

Hi,

Thanks for your waiting.
Our Spire.Email supports getting body html from message, and our Spire.Doc supports converting word to image, hence you can achieve your need to convert mailbody with original style to image using the both products. Please refer to the following sample code. However, the inline images in body html cannot be obtained at present. Our Dev team is still working on the feature, if it is available, we will inform you.
Download link of Spire.Email: Spire.Email Pack(hot fix) Version:2.4.0
Download link of Spire.Doc: Spire.Doc Pack Version:7.7

Code: Select all
MailMessage mail = MailMessage.Load("sample.msg");
string htmlBody = mail.BodyHtml;
Document doc = new Document();
Section section = doc.AddSection();
Paragraph p = section.AddParagraph();
p.AppendHTML(htmlBody);
Image image=doc.SaveToImages(0, ImageType.Bitmap);
image.Save("result.png", System.Drawing.Imaging.ImageFormat.Png);
Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Thu Sep 12, 2019 11:24 am

Hi,

Thanks for your patient waiting.
Now the msg which has the inline images in body html could be converted to Pdf file successfully. Please download the hotfix from the following link and use the code I provided previously.
https://www.e-iceblue.com/downloads/TempVersion/spire.office_4.9.1.zip

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1195
Joined: Tue Sep 27, 2016 1:06 am

Tue May 09, 2023 2:10 am

thanks
User avatar

zaki.zou
 
Posts: 3
Joined: Fri Jun 16, 2017 2:35 am

Return to Spire.Email