Mailkit: Show Email As HTML

Created on 26 Apr 2017  路  8Comments  路  Source: jstedfast/MailKit

To help me debug your issue, please explain:

  • What were you trying to do?
  • What happened?
  • What did you expect to happen?
  • Step-by-step reproduction instructions and/or a simple test case.

If you got an exception, please include the exception Message and StackTrace.

If you got an exception such as Syntax error in XYZ. Unexpected token: ...,
INCLUDE THE PROTOCOL LOG (scrubbed of any authentication data). If you do not include
the protocol log, you will make me VERY UNHAPPY.

To get a protocol log, follow one of the following code snippets:

// log to a file called 'imap.log'
var client = new ImapClient (new ProtocolLogger ("imap.log"));
// log to a file called 'pop3.log'
var client = new Pop3Client (new ProtocolLogger ("pop3.log"));
// log to a file called 'smtp.log'
var client = new SmtpClient (new ProtocolLogger ("smtp.log"));

Note: if the protocol log contains sensitive information, feel free to email it to me at
[email protected] instead of including it in the GitHub issue.

question

Most helpful comment

How much would you be willing to pay for my time? I have very little of my own free time to do things that I enjoy and this might take me a few hours to write for you.

All 8 comments

Hello,

I am getting new messages in a mailbox with mailkit and saving to local folder. I want to save email as html format. How can I do this? The screenshot that I want is attached to the case.
image

You'll have to read the FAQ.

Pay close attention to the HtmlPreviewVisitor and use a similarly written custom class of your own to format whatever headers you want to show as HTML as well.

I used this class but I cant achieve. Can you help me, please?

What part are you struggling with?

The code you shared is
void Render (MimeMessage message)
{
var tmpDir = Path.Combine (Path.GetTempPath (), message.MessageId);
var visitor = new HtmlPreviewVisitor (tmpDir);

Directory.CreateDirectory (tmpDir);

message.Accept (visitor);

DisplayHtml (visitor.HtmlBody);
DisplayAttachments (visitor.Attachments);

}

But the visitor did not show that I wanted.

Right, you'll have to modify it to print out the message headers that you want as well.

How can I do that, please help me. Can you send me a sample?

How much would you be willing to pay for my time? I have very little of my own free time to do things that I enjoy and this might take me a few hours to write for you.

Was this page helpful?
0 / 5 - 0 ratings