Converting a MIME Tree to MailMessage

I am writing a C # program that processes and forwards email messages. I have a POP3 library and a MIME parser, and I need to copy the MIME tree to System.Net.Mail.MailMessage.

What is the best way to map the various parts of MIME to AlternateViews, LinkedResources, and Attachments?

EDIT : this will work with all email clients (both sending and receiving)

+3
source share
5 answers

Now I am copying something with Content-Dispositionthat which is not inline, or with the MIME category of everything except text or image, on Attachment, nothing inlineor something else with the MIME category Imageup LinkedResourcein the HTML view or in the last view, and something else like AlternateView. (I have not tested this yet)

0
source

From a review of 10,000 feet, this is what I will do.

Flatten mime pieces in a tree. Make sure that each part contains 1 and only 1 part (not the parent, such as multipart / related or something similar).

  • Check the following body conditions:

    • If the first part is HTML, install it in the body of the message

    • If the first part is plain text and the second part is not html, set the plain text part to the body of the message.

    • , - html, 2 . *** , Content-Disposition: attachment.

  • . ,

    • ,

    • .

      , LinkedResource ( HTML).

99% .

+2

(/plain, text/html ..), / AlternateView. , AlternateView, , , .

LinkedResource, Content-Disposition.

Content-Disposition , .

Content-Disposition Content-Disposition LinkedResource. , , Content-ID , , , LinkedResources /html AlternateView ( AlternateView, , AlternateView text/html).

+1

, , "" e-mail

0

, System.Net.Mail.MailMessage?

System.Net.Mail.MailMessage offers only a very small subset of what MIME offers. So, if your MIME parser is aimed at supporting all / most of the standard functions, your goal of copying the MIME message to MailMessage will be difficult at best and impossible at worst. Does the POP3 library provide SMTP access? If so, I would leave System.Net.Mail.MailMessage alone and go with what the thrid party library provides.

0
source

Source: https://habr.com/ru/post/1710564/


All Articles