Email Parsing With OpenPop.Pop3 (OpenPop.NET)

Article Overview

  • Background
  • Pre-requisites
  • How to perform email parsing
    • Connect with Server
    • Authenticate to Server
    • Go through all email
    • Get email content
    • Process email content
  • Whole example together
    • References, Page load, Model, Table
    • Get all emails and set in table
    • Get email content
    • Set email content in table
    • Output
  • Summary

Background

 
There was a requirement where I had to read emails from an email box, and after that I had to process each email to generate a record into the database. There are various libraries using which you can perform email parsing.
 
OpenPop.NET is a robust open source POP3 client and MIME parser written in C#. Here, I am putting all the key details at one place with entire examples.
 

Prerequisites

 
You MUST have basic knowledge of C#, ASP .NET, and Email Parsing.
 
Download “OpenPop.dll” from OpenPop.NET.

How to perform email parsing

 
There are mainly five steps to perform email parsing:
  • Connect with Server
  • Authenticate to Server
  • Go through all email
  • Get email content
  • Process email content
Now, let us see in detail.
 
Connect with Server
 
You need host (server) name, port number, etc. details to connect with the POP3 email server.
 
objPOP3Client.Connect(host, port, useSsl);
 
Authenticate to Server
 
Once the server is connected you have to authenticate it using email (username) and password. This is your email box login details.
 
objPOP3Client.Authenticate(user, password);
 
Go through all email
 
After successful authentication you have to loop through each email one by one.
 
objMessage = objPOP3Client.GetMessage(intMessageNumber);
 
Process email content
 
Now, you can process email content for your own process. For, example insert email message into the database for further processing.
 

Complete example

 
For the complete example, I have prepared and uploaded a cs file which contains all the code.
  • References, Page load, Model, Table
  • Get all emails and set in table
  • Get email content
  • Set email content in table
  • Output
References, Page load, Model, Table
 
Email Parsing With OpenPop.Pop3 (OpenPop.NET)
 
Email Parsing With OpenPop.Pop3 (OpenPop.NET)
 
Email Parsing With OpenPop.Pop3 (OpenPop.NET)
 
Email Parsing With OpenPop.Pop3 (OpenPop.NET)
 
Get all emails and set in table
 
Email Parsing With OpenPop.Pop3 (OpenPop.NET)
 
Get email content
 
Email Parsing With OpenPop.Pop3 (OpenPop.NET)
 
Set email content in table
 
Email Parsing With OpenPop.Pop3 (OpenPop.NET)
 
Output
 
Email Parsing With OpenPop.Pop3 (OpenPop.NET)
 

Summary

 
Now, I believe you will be able to perform email parsing with OpenPop.Pop3 (OpenPop.NET).