4AspNet POP3 .NET Component

EmailMessage.Parse Method (String)

Creates an EmailMessage object from the specified string. Can be used to parse emails stored as text files.

[Visual Basic]
Overloads Public Shared Function Parse( _
   ByVal emailText As String _
) As EmailMessage
[C#]
public static EmailMessage Parse(
   string emailText
);

Parameters

emailText
Text for parsing

Return Value

EmailMessage object

Example

This sample shows how to use the Parse method to grab all attached files from emails stored local

ForAspNet.POP3.License.LicenseKey = "<put license string here>";
DirectoryInfo dir = new DirectoryInfo(@"c:\\pop3emails\");
FileInfo[] files = dir.GetFiles();
for(int i = 0; i < files.Length; i++)
{
    StreamReader sr = new StreamReader(files[i].FullName);
    EmailMessage objEmail = EmailMessage.Parse(sr.ReadToEnd());
    Console.WriteLine("----------------------------------");
    Console.WriteLine("File: " + files[i].FullName);
    if (objEmail.IsAnyAttachments)
    {
        for(int a = 0; a < objEmail.Attachments.Count; a++)
        {
            Attachment attFile = (Attachment)objEmail.Attachments[a];
            if (attFile.IsFileAttachment) 
                attFile.Save(@"c:\\attachments\" + attFile.FileName);
            else
                if (attFile.ContentType == "message/rfc822")
                {
                    FileStream fs = new FileStream(@"c:\\attachments\attachedmessages\" + i.ToString() + ".eml", FileMode.Create);
                    fs.Write(attFile.Data, 0, attFile.Data.Length);
                    fs.Close();
                }
        }
        
    }
}

See Also

EmailMessage Class | ForAspNet.POP3 Namespace | EmailMessage.Parse Overload List