Are there .NET Framework methods to parse an email (MIME)?

前端 未结 6 1429
遇见更好的自我
遇见更好的自我 2020-12-02 19:12

Is there a class or set of functions built into the .NET Framework (3.5+) to parse raw emails (MIME documents)?

I am not looking for anything fancy or a separate lib

相关标签:
6条回答
  • 2020-12-02 19:34

    I know you said no external libraries, but I have a library posted on codeplex:

    https://bitbucket.org/otac0n/mailutilities

    MimeMessage msg = new MimeMessage(/* string, stream, or Byte[] */);
    

    It has been tested with over 40,000 real-world mail messages.

    I'm not too happy with my namespace choice, but... I'm too lazy to change it.


    PS:

    Internally, my library uses these regexes as a parser:

    internal static string FullMessageMatch =
        @"\A(?<header>(?:[^\r\n]+\r\n)*)(?<header_term>\r\n)(?<body>.*)\z";
    internal static string HeadersMatch =
        @"^(?<header_key>[-A-Za-z0-9]+)(?<seperator>:[ \t]*)(?<header_value>([^\r\n]|\r\n[ \t]+)*)(?<terminator>\r\n)";
    internal static string HeaderSeperator =
        "\r\n";
    internal static string KeyValueSeparator =
        @"\A:[ \t]*\z";
    
    0 讨论(0)
  • 2020-12-02 19:48

    I recommend IMAP and MIME parser libs from Lumisoft. Which I used before and its easy to work with. You can download it from here: http://www.lumisoft.ee/lsWWW/Download/Downloads/Net/ The lib has many other protocols like ftp, pop3, etc and I'm sure the sc is available. Try to google for it, also you can find it on codeproject.com regards

    0 讨论(0)
  • 2020-12-02 19:50

    No, there is no way to do that yet. Microsoft has not created a Text-to-Message convertor just as they haven't created a POP3 or IMAP library. Unfortunate.

    0 讨论(0)
  • 2020-12-02 19:50

    check out our Rebex Secure Mail which includes a (IMHO) decent S/MIME parser. Features include:

    • High level MailMessage API (message as seen in common email client)
    • Low level MimeMessage API (access to S/MIME internal tree)
    • Support for both MIME, S/MIME
    • Support for TNEF (winmail.dat) produced by Microsoft Outlook
    • Message encryption
    • Message signing
    • Unicode and internationalization support
    • Linked resources list (used for inline CSS and pictures in HTML mails)
    • IEnumerable<T> support (needed for LINQ)
    • supports all .NET and .NET compact frameworks released until today

    The parser is part of Rebex Secure Mail and you can download it here.

    0 讨论(0)
  • 2020-12-02 19:50

    Check out Mail.dll .NET mail component, it has build in MIME support, unicode, and multi-national email support:

    MailBuilder builder = new MailBuilder();
    
    // Here you get the message class with attachments, visuals
    IMail message = builder.CreateFromEml(File.ReadAllText("test.eml"));
    
    // you can access entire MIME document:
    MimeDocument document = message.Document;
    

    Please note that Mail.dll is a commercial product that I've created.

    You can download it here: https://www.limilabs.com/mail.

    0 讨论(0)
  • 2020-12-02 19:56

    Very impressed with free, open-source (MIT-licensed) and fast MimeKit

    • Nuget: https://www.nuget.org/packages/MimeKit
    • "Lite" version without the crypto stuff: https://www.nuget.org/packages/MimeKitLite
    0 讨论(0)
提交回复
热议问题