Version: 3.2.1.0
Send, receive, edit, sign/verify and encrypt/decrypt email messages in any .NET application or service. 

Pop Messages Code Example

The following example demonstrates getting specific messages from a mail server using the PowerTCP Pop component. Progress is provided while messages are downloaded.

< Back to all samples for PowerTCP Mail for .NET

private void getMessages_Click(object sender, EventArgs e)
{
    try
    {
        //Setup the session - start by getting all message headers.
        //Do not automatically delete these messages.
        //Do not automatically logout after getting the headers.
        pop1.AutoGet = MessageSection.Header;
        pop1.AutoDelete = false;
        pop1.AutoLogout = false;

        //Login to the POP server and get message headers.
        pop1.Login("myMailServer""myAccount""myPassword");
        if (pop1.Messages.Length > 0)
        {
            //Get all messages from a specified address and add the
            //Subject line to a list.
            char[] brackets = { '<''>' };
            foreach (PopMessage pm in pop1.Messages)
            {
                if (pm.Message.From.Address.Trim(brackets) == "important@gmail.com")
                {
                    pm.Get();
                    textList.AppendText(pm.Message.Subject + Environment.NewLine);
                }
            }
        }

        //Logout.
        pop1.Logout();
        MessageBox.Show("DONE!");
    }
    catch (Exception ex)
    {
        //Show error messages.
        MessageBox.Show("ERROR: " + ex.Message);
    }
}

private void pop1_Progress(object sender, PopProgressEventArgs e)
{
    //Show progress of each message as it is downloaded.
    progressBarMessage.Maximum = 100;
    progressBarMessage.Value = (int)((e.Position * 100) / e.Length);
}