PowerTCP Mail for .NET | POP Code Example

See all PowerTCP Mail for .NET Code Examples

POP Example

This example demonstrates downloading messages via POP and saving them to disk.

 

Pop pop1 = new Pop();
//Connect and log into the account
pop1.Session.RemoteEndPoint = new Dart.Mail.IPEndPoint("myPopServer.com", Pop.GetDefaultPort(pop1.Session));
pop1.Session.Username = "myUsername";
pop1.Session.Password = "myPassword";
pop1.Connect();
pop1.Authenticate(false, true);

//Download all messages in the account and save them to disk with a unique name
string messageFolder = Application.StartupPath + "\\messages\\";
foreach (PopMessage pMessage in pop1.Messages)
{
    pMessage.Get();
    //Save the message to disk, or access pMessage.Message.Text, Html or Attachments, etc.
    pMessage.Message.Save(messageFolder + pMessage.Id.ToString("D4") + ".eml");
}

//Gracefully logout of the session
pop1.Close();

 

To download a trial please visit the PowerTCP Mail for .NET product page.