Retrieve email content using C #

I have a file containing an email message. I was wondering if there is any built-in library or class in .net that would allow me to directly extract the contents of the email something like this

Lx library = new library ("email_file");

Console.writeline (lx.From ());

Console.WriteLine (lx.To ());

file attachment = lx.attachment ();

I wrote a program that will perform these tasks by scanning a file containing an email message using a regular expression and extracting a separate field from the email, for example: To, From, Attachment, etc. but the requirement is to extract these things using the built-in library or class.

Any help would be greatly appreciated.

+3
source share
3 answers

There is no direct support for reading email messages in .NET. You have to hack your own (in a day or two you will probably be able to process 95% of regular eml emails, after several months of hard work you will be able to process the remaining 5%). A complete email analysis means the correct handling of international characters, attachments, several encoding schemes, attachments, email messages sent as attachments, encrypted and signed emails to be able to handle common errors of popular email clients, etc.

There are two common email file formats:

EML , * nix, . Outlook Express Thunderbird / eml. .NET SmtpClient PickupDirectory, . EML RFC 2045, 2046, 2047, 2048, 2049, 2822.

eml. Rebex Secure Mail ( Google).

using Rebex.Mail;
using Rebex.Mime.Headers;

// create an instance of MailMessage  
MailMessage message = new MailMessage();

// load the message from a local disk file  
message.Load("c:\\message.eml");

Console.Write(message.From);
Console.Write(message.To)
foreach (Attachment attachment in message.Attachments)
{
    // Save the file 
    Console.WriteLine ("Saving '{0}' ({1}).", 
     attachment.FileName, attachment.MediaType);
    attachment.Save (attachment.FileName);
}

.

MSG , Outlook. Microsoft . #, . , .

+5

, . ?

Outlook, Outlook interop.

0

, , , aspnetemail.com.

- , - ( ) aspnetemail .

, , .

0

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


All Articles