I'm currently using POP. Here is the code so far:

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Net.Sockets;
using System.Text.RegularExpressions;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            TcpClient tcpclient = new TcpClient();
            tcpclient.Connect("pop.gmail.com", 995);

            System.Net.Security.SslStream sslstream = new SslStream
(tcpclient.GetStream());
            sslstream.AuthenticateAsClient("pop.gmail.com");

            System.IO.StreamWriter sw = new StreamWriter(sslstream);
            System.IO.StreamReader reader = new StreamReader
(sslstream);

            sw.WriteLine("USER [email protected]");
            sw.Flush();

            sw.WriteLine("PASS password");
            sw.Flush();

            sw.WriteLine("RETR 1"); //Retrieve email - only retrieves
one email, first one in inbox, need to get all unread messages
            sw.Flush();

            sw.WriteLine("Quit"); //Close the connection
            sw.Flush();

            string str = string.Empty;
            string strTemp = string.Empty;
            string Body = string.Empty;
            string Subject = string.Empty;
            string ReferenceNumber = string.Empty;

            while ((strTemp = reader.ReadLine()) != null)
            {
                if (strTemp.Contains(" task:") == true)
                {
                    int SubjectIndex = strTemp.IndexOf("task");
                    SubjectIndex += 5;
                    ReferenceNumber = strTemp.Substring(SubjectIndex,
8);
                }

                if (strTemp == ".")
                {
                    break;
                }

                if (strTemp.IndexOf("-ERR") != -1)
                {
                    break;
                }

                str += strTemp;
            }

                if (str.LastIndexOf(" quoted-printable") != -1)
                {
                    int Index = str.LastIndexOf(" quoted-printable");
                    Index += 17;
                    int NewIndex = str.IndexOf(" Information"); //Get
starting position of trailing data
                    NewIndex -= 20;
                    int NewLength = NewIndex - Index;

                    Body = str.Substring(Index,NewLength); //Only
extract body of email
                    Response.Write(Body); //Display the message
                 }
        }

        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
   }
}

I'm currently at a loss on how to proceed from here. I've tried using
the LIST command, but it returns message ID's and the size of the
mails, which is not what I'm looking for. Is there another command I
can use?

Thanks
Lauren

On Nov 9, 5:11 pm, Mike Fry <[email protected]> wrote:
> Jamie Fraser wrote:
> > Post a code sample please - we have no idea what libraries you are using
> > and therefore cannot advise.
>
> Also, are you familiar with the POP protocol?
>
> --
> Best regards,
> Mike Fry
> Johannesburg.

Reply via email to