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.
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
Get all emails and set in table
Get email content
Set email content in table
Summary
Now, I believe you will be able to perform email parsing with OpenPop.Pop3 (OpenPop.NET).