Login Login
MORE

WIDGETS

Widgets

Wanted articles
Who is online?
Article tools

CSharp:Outlook Email

From Aino Wiki

Jump to: navigation, search

MSGReader

Per elaborare files *.msg e *.eml

Dopo aver installato la libreria con NuGet non c'è neanche bisogno di istanziarla con lo Using.

strFileNameFullPath = TxtEmailPath.Text + "\\" + TxtEmailFilename.Text;
MsgReader.Outlook.Storage.Message outlookMsg = new MsgReader.Outlook.Storage.Message(strFileNameFullPath);

TxtLog.Text += string.Format("{0}\r\n", outlookMsg.BodyText);

Esempio ufficiale:

using (var msg = new MsgReader.Outlook.Storage.Message("d:\\testfile.msg"))
{
        var from = msg.Sender;
        var sentOn = msg.SentOn;
        var recipientsTo = msg.GetEmailRecipients(MsgReader.Outlook.RecipientType.To, false, false);
        var recipientsCc = msg.GetEmailRecipients(MsgReader.Outlook.RecipientType.Cc, false, false);
        var subject = msg.Subject;
        var htmlBody = msg.BodyHtml;
        // etc...
}

Lettura di Proprietà:

var fileInfo = new FileInfo("d:\\testfile.eml");
var eml = MsgReader.Mime.Message.Load(fileInfo);

if (eml.Headers != null)
{
        if (eml.Headers.To != null)
        {
            foreach (var recipient in eml.Headers.To)
            {
                var to = recipient.Address;            
            }
        }
}

var subject = eml.Headers.Subject;

if (eml.TextBody != null)
{
        var textBody = System.Text.Encoding.UTF8.GetString(eml.TextBody.Body);
}

if (eml.HtmlBody != null)
{
        var htmlBody = System.Text.Encoding.UTF8.GetString(eml.HtmlBody.Body);
}

// etc...

Mappa e Link


C# | Librerie e PlugIn


Visual Studio | MS SQL | Dizionario


Parole chiave:

Author