Dev Direct Solution Center

For more information and to buy this product...

How to get e-mail messages from a POP3 account

  For a copy of the sample project please click here to download and install the product evaluation.

Introduction

Shows how the wodPop3 ActiveX Component is used to access a mailbox on the server using the POP3 protocol. Mail found on the server can be retrieved locally as complete messages or only headers, and/or can be deleted from the server. A full set of commands for standard operations is supported.

Detail

By using our wodPop3 component we can simply supply our account information and connect to server. The component will get a count of the available messages and then let us retrieve them. In this example, we retrieve them all using the GetAll method.

After downloading the messages (which is done automatically), we can access each of them through the Messages collection and save them locally.

Set up

Download and run the executable from the above link. The samples will be placed in directory C:\Program Files\WeOnlyDo.Com\Pop3\Samples. There are example projects for C# and VB6.

In the VB6 wodPop3Com and C# WODPOP3COMLib.wodPop3Com is referenced with a form-wide variable called Pop3.

Connecting to the server

A connection is initiated when the form is initialised. In order for this sample to work, you need to specify your own details for Hostname, Login and Password.

When the Blocking property is set to True it will cause the execution of the next method to be delayed until previous method has finished.

The Connect method will initialize the connection with server.

VB6
Pop3.HostName = "your_pop3_server_address" Pop3.Login = "your_login" Pop3.Password = "your_password" 'tells the component to block execution while methods are running Pop3.Blocking = True 'connect to server Pop3.Connect
C#
Pop3.Hostname = "your_pop3_server_address"; Pop3.Login = "your_login"; Pop3.Password = "your_password"; //tells the component to block execution while methods are running Pop3.Blocking = true; //connect to server Pop3.Connect();

Get all available messages

The GetAll method will download all the messages in the mailbox from the server to local files. After each message has been received, the Received event will be fired which enables you to inspect message the content immediately if you wish.

In this example we aren't using events and all messages will be download to local files.

VB6
Pop3.Messages.GetAll
C#
Pop3.Messages.GetAll();

Disconnect

The Disconnect method will disconnect wodPop3 from the server as we don't need connection any more.

VB6
Pop3.Disconnect
C#
Pop3.Disconnect();

View downloaded messages

The Pop3Msgs collection (Pop3.Messages) holds a collection of all messages retreived from the server. It can be used to examine the received messages.

This example will show sender of each downloaded message and save the message to a local file. You can also acccess all other useful message information via properties such as Subject, Body, Attachment, From, Date etc.

VB6
Dim i As Integer For i = 0 To Pop3.Messages.Count - 1 MsgBox i & ". From: " & Pop3.Messages(i).From Pop3.Messages(i).Save App.Path & "\" & i & ".txt" Next i
VB6
short i; for (i = 0; i <= Pop3.Messages.Count - 1; i++) { MessageBox.Show(i + ". From: " + Pop3.Messages[i].From); Pop3.Messages[i].Save("C:\\" + i + ".txt"); }

Summary

This simple demonstration shows how wodPop3 can easily and automatically download email messages from a server and save them to a local file.

Visit WeOnlyDo! Inc. for more information and more samples.