Searching POP3 accounts for bounced emails with vb.net

In this article I am going to demonstrate how to develop an application in VB.net that allows you to search a list of POP3 email addresses and return all of the bounced email addresses from that email.  For ease of learning, we will create a simple single threaded console app.  This should work for most people, but to expand on this article, try adding asynchronization and multiple threads.

Before we begin we will assume you already have either Visual Studio 2010 or VB.net Express 2010 installed.  Please note we will be using Visual Studio 2010 professional edition in this. We will also be using a 3rd party class which will handle all of our POP3 protocol coding.  In order to download the latest copy of this class, head on over to their CodePlex project website Mailsystem.NET.  Just unzip the files to a location you can easily fine and will not delete (I have a folder d:\COM Objects that I put all new class objects in) and load up visual studios.

1. Create A New Project

To start, we will create a new console project

  • Click File -> New -> Project
  • Select Visual Basics from the left treeview menu and click on Console Application
  • For name, lets name it “”.
  • Also name the Solution “Bounced Email Dumper”
  • Make sure “Create directory for solution” is selected and press “OK”

You  now have the base project created!

2. Project Clean Up / Method Setup

Now that you have the project created, lets clean the project up a bit and create the core coding for this project.

  1. Right click on “Module1.vb” in the Solution Explorer, and lets rename it to “main.vb”.  Double click on the file to open it up and source view and make sure it is now called “Module Main” instead of “Model Module1″.  If it is not, rename it.
  2. Double click on “My Project”  and go to the “Application” tab.  Make sure for startup object you have “Sub Main” selected.
  3. We must now add our references.  Still in the application settings, click on the “References” tab and click “Add”.  Once the “Add Reference” dialog pops up, select the “Browse” tab.  At this point, go to the folder you extracted the MailSystem.NET class to and include “ActiveUp.Net.Pop3.dll”.  You will also want to include “ActiveUp.Net.Common.dll”

Now that we have our project setup as we needed, lets go ahead and add our core methods, variables and includes.  For this we will need to create a structure that can hold all of the information for a single account, a list to hold all of our accounts left to process, a method to load our POP3 accounts for a specific folder, a method to process a specific POP3 account, and a StreamWriter to write our bounced emails to.  So at this point we have our class as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Module Main
 
  ''' <summary>
  ''' This will hold all of our accounts
  ''' </summary>
  ''' <remarks></remarks>
  Private accounts As New List(Of Account)
 
  ''' <summary>
  ''' This will hold our writer that we send the bounces to
  ''' </summary>
  ''' <remarks></remarks>
  Private writer As IO.StreamWriter
 
  ''' <summary>
  ''' Holds how many bounce requests we found
  ''' </summary>
  ''' <remarks></remarks>
  Private bounceCount As Integer = 0
 
  ''' <summary>
  ''' This will be all of our accounts that we need to go through
  ''' </summary>
  ''' <remarks></remarks>
  Private Structure Account
    Public username As String
    Public password As String
    Public server As String
    Public port As Long
  End Structure
 
  Sub Main()
 
  End Sub
 
  ''' <summary>
  ''' This will load all of our pop3's into an array of username:password
  ''' </summary>
  ''' <returns></returns>
  ''' <remarks></remarks>
  Private Function Load_POP3(file As String)
    Return False
  End Function
 
  ''' <summary>
  ''' This will get all the bounce requests for a specific account
  ''' </summary>
  ''' <param name="acc"></param>
  ''' <param name="minimum_level">The min level we will look for when deciding if it's a bounced email</param>
  ''' <param name="err">if there is an error, it will be held here</param>
  ''' <returns></returns>
  ''' <remarks></remarks>
  Private Function Process_Account(acc As Account, ByVal minimum_level As Integer, ByRef err As String) As Boolean
    Return False
  End Function
 
End Module
Pages:
  1. very nice website, enjoy the way you write, you definitely do hold a flair for writing, will be viewing this website quite often

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">