Question

I'm trying to read through a gmail account to get gps data that is being sent there ( in the text of a email) from an moble phone (my phone)

using (Pop3Client cl = new Pop3Client())
            {
                cl.UserName = "crash893";
                cl.Password = "password";
                cl.ServerName = "pop.gmail.com";
                cl.AuthenticateMode = Pop3AuthenticateMode.Pop;
                cl.Ssl = true;
                cl.Authenticate();
                ///Get first mail of my mailbox
                Pop3Message mg = cl.GetMessage(1);  <<<<<<<<<< ERROR
                String MyText = mg.BodyText;
                ///If the message have one attachment
                Pop3Content ct = mg.Contents[0];
                ///you can save it to local disk
                ct.DecodeData("c:\\test.txt");
            }

but I get a exception on the "get first mail of mailbox message

"Higuchi.Net.Pop3.Pop3ConnectException: Pop3 connection is closed
at Higuchi.Net.Pop3.Pop3Client.SendCommand(String inCommand)
at Higuchi.Net.Pop3.Pop3Client.Execute(String inCommand, Boolean inIsMultiLine)
at Higuchi.Net.Pop3.Pop3Client.Execute(Pop3Command inCommand)
at Higuchi.Net.Pop3.Pop3Client.GetMessage(Int64 inMailIndex)"}

Ideally what i would like to do is open this read all the new unread emails in this account for a certain subject line then read the data in the body and mark them as read

does anyone know why its erroring out

does anyone have any experince with c#mail that hey could point me in the right direction for reading and makring emails as read etc

Was it helpful?

Solution 3

        using (Pop3Client cl = new Pop3Client())
        {
            cl.UserName = "ewgsdssw";
            cl.Password = "sdgwsegw";
            cl.ServerName = "pop.gmail.com";
            cl.AuthenticateMode = Pop3AuthenticateMode.Pop;
            cl.Port = 995;
            cl.Ssl = true;
            cl.Authenticate();
            ///Get first mail of my mailbox
            ///
            int total = Convert.ToInt16(cl.GetTotalMessageCount());

            while (total >= 1)
            {
                Pop3Message mg = cl.GetMessage(total);
                if (mg.Subject == "I am Here")
                {

                    // http://maps.google.com/maps?q=38.89552,-77.43265
                    //(+/- 76 metres.)

                    string location = mg.BodyText;
                    location = location.Replace("http://maps.google.com/maps?q=","~");
                    location = location.Replace("metres.)\r\n\r\n","~");

                    location = location.Split('~')[1];

                    location = location.Replace("(+/- ", ",");
                    location = location.Replace("\r\n", "");


                    string[] data = location.Split(',');
                    string lat = data[0];
                    string lon = data[1];
                    string res = data[2];
                    DateTime time = mg.Date;

                    textBox1.AppendText(string.Format("Lat: {0} LON: {1} Res: {2} TIME: {3}\r\n",lat,lon,res,time.ToString()));

                }

                total--;
            }

        }

OTHER TIPS

It is not possible to mark emails as read using the POP protocol.

Try using IMAP.

cl.Port = 995;

I do not have experience with C#Mail, and this answer may not help, but I've experienced weirdness in the past while trying to write email send/receive related code.

Turned out the antivirus software we were running at work had a whitelist of allowed .EXE's that could make in/outbound POP3 or SMTP connections. Any chance this is your problem?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top