Click here to Skip to main content
15,921,622 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem in updating multiple rows of a single column of a single table using Update Command from C# Pin
Member 236780010-Nov-09 21:43
Member 236780010-Nov-09 21:43 
Question3d rendering Pin
LimitedAtonement9-Nov-09 7:03
LimitedAtonement9-Nov-09 7:03 
AnswerRe: 3d rendering Pin
harold aptroot9-Nov-09 7:45
harold aptroot9-Nov-09 7:45 
GeneralRe: 3d rendering Pin
LimitedAtonement9-Nov-09 7:48
LimitedAtonement9-Nov-09 7:48 
GeneralRe: 3d rendering Pin
harold aptroot9-Nov-09 8:56
harold aptroot9-Nov-09 8:56 
GeneralRe: 3d rendering Pin
LimitedAtonement9-Nov-09 10:08
LimitedAtonement9-Nov-09 10:08 
GeneralRe: 3d rendering Pin
harold aptroot9-Nov-09 10:29
harold aptroot9-Nov-09 10:29 
QuestionMultithread email reader!!! Pin
Christian_V_V9-Nov-09 4:57
Christian_V_V9-Nov-09 4:57 
Hi Dear all.

I`m not a C# programmer , but I manage to make a little email Pop3 reader searching in the internet. This program has a timer and every 5 min looks into an email account and read and download some information. Now what I need is the possibility to read mails from more than one email account at the same time. IE, if I have two Gmail account, the program should look into this two account every 5 min and download the info I need. Please, anyone that help me on this. I´m using Higuchi.net lib for connecting to email accounts, it´s a very good one, anybody can google it and download it, it is free. I have tried multithreading but with no luck. My code is the following:

public partial class Pop3 : Form
    {
        public Pop3()
        {
            InitializeComponent();
        }
      
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.checkBox2.Checked != true && this.checkBox3.Checked != true && this.checkBox1.Checked != true)
            {
                MessageBox.Show("Select a Conection Option");
            }
            else
            {
                timer1.Tick += new System.EventHandler(this.OnTimerTick);
                timer1.Enabled = true;
                timer1.Start();
                this.button1.Enabled = false;
            }
        }

        private void OnTimerTick(object sender, EventArgs e)
        {
            
            if (this.checkBox2.Checked == true)
                Gmail();

            if (this.checkBox3.Checked == true)
                Gmail2();

            if (timer1.Interval != 360000)
                timer1.Interval = 360000;
        }

       
        private void Gmail()
        {
            Pop3Client cl = new Pop3Client(); 
            cl.UserName = "xxxxxxxxx@gmail.com";
            cl.Password = "xxxxxxxxx";
            cl.ServerName = "pop.gmail.com";
            cl.Port = 995;
            cl.AuthenticateMode = Pop3AuthenticateMode.Pop;
            cl.Ssl = true;
            cl.Authenticate();

            if (cl.Available == true)
            {
                if (cl.ReceiveTimeout <= 10000)
                {
                    if (cl.State == Pop3ConnectionState.Authenticated)
                    {
                        if (Convert.ToInt32(cl.GetTotalMessageCount()) >= 1)
                        {
                            try
                            {
                                int ncount = Convert.ToInt32(cl.GetTotalMessageCount());
                                for (int i = 1; i <= ncount; i++)
                                {
                                    Pop3Message mg = cl.GetMessage(i);
                                    string MyText1 = mg.BodyText;
                                    Parse(MyText1);
                                }
                                for (int i = 1; i <= ncount; i++)
                                {
                                    cl.DeleteEMail(i);
                                }
                            }
                            catch (Exception e)
                            {
                                throw new Exception(e.Message);
                            }
                        }
                    }
                    else
                    {
                        popup mypop = new popup();
                        mypop.Show();
                        mypop.Refresh();
                    }
                }
            }
            cl.Close();
            cl.Dispose();
        }

        private void Gmail2()
        {
            Pop3Client cl = new Pop3Client();
            cl.UserName = "xxxxxxxx@gmail.com";
            cl.Password = "xxxxxxxxxxxx";
            cl.ServerName = "pop.gmail.com";
            cl.Port = 995;
            cl.AuthenticateMode = Pop3AuthenticateMode.Pop;
            cl.Ssl = true;
            cl.Authenticate();

            if (cl.Available == true)
            {
                if (cl.ReceiveTimeout <= 10000)
                {
                    if (cl.State == Pop3ConnectionState.Authenticated)
                    {
                        if (Convert.ToInt32(cl.GetTotalMessageCount()) >= 1)
                        {
                            try
                            {
                                int ncount = Convert.ToInt32(cl.GetTotalMessageCount());
                                for (int i = 1; i <= ncount; i++)
                                {
                                    Pop3Message mg = cl.GetMessage(i);
                                    string MyText1 = mg.BodyText;
                                    Parse(MyText1);
                                }
                                for (int i = 1; i <= ncount; i++)
                                {
                                    cl.DeleteEMail(i);
                                }
                            }
                            catch (Exception e)
                            {
                                throw new Exception(e.Message);
                            }
                        }
                    }
                    else
                    {
                        popup mypop = new popup();
                        mypop.Show();
                        mypop.Refresh();
                    }
                }
            }
            cl.Close();
            cl.Dispose();
        }


        private void Parse(string xtext1)
        {
            string[] xxValues = Regex.Split(xtext1, "\r\n");
            for (int j = 0; j < xxValues.Length; j++)
            {
                string vf_values = xxValues[j].ToString();

                if (vf_values != "")
                {
                    string[] values = vf_values.Split(new char[] { ' ' });
                    string date = values[0];
                    string time = values[1].Remove(values[1].Length - 1);
                    string unit = values[2].Remove(values[2].Length - 1);
                    string clock = values[3];
                    string speed = vf_values.Substring(vf_values.Length - 11, 8);
                    string xSpeed;
                    string cSpeed = "";
                    for (int i = 0; i < speed.Length; i++)
                    {
                        xSpeed = speed.Substring(i, 1);
                        Regex re = new Regex(@"\d+");
                        Match m = re.Match(xSpeed);
                        if (m.Success)
                            cSpeed += xSpeed;
                    }

                    conexion con = new conexion();
                    con.Insert(date, time, unit, clock, cSpeed);
                    con.closingcon();

                    dataGridView1.Rows.Add(1);
                    dataGridView1.Rows[j-1].Cells[0].Value = date;
                    dataGridView1.Rows[j-1].Cells[1].Value = time;
                    dataGridView1.Rows[j-1].Cells[2].Value = unit;
                    dataGridView1.Rows[j-1].Cells[3].Value = clock;
                    dataGridView1.Rows[j-1].Cells[4].Value = cSpeed;
                    dataGridView1.FirstDisplayedScrollingRowIndex = j;
                    dataGridView1.Refresh();
                    dataGridView1.CurrentCell = dataGridView1.Rows[j-1].Cells[0];
                    dataGridView1.Rows[j].Selected = true;

                    this.textBox1.Text = j.ToString();
                    this.textBox1.Refresh();
                }
            }
            dataGridView1.FirstDisplayedScrollingRowIndex = 1;
            dataGridView1.Refresh();
            dataGridView1.CurrentCell = dataGridView1.Rows[1].Cells[0];
            dataGridView1.Rows[1].Selected = true;
        }

        private void Pop3_Load(object sender, EventArgs e)
        {
            dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 9, FontStyle.Bold, GraphicsUnit.Point);
            dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = SystemColors.ControlDark;
            dataGridView1.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single;
            dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 8, FontStyle.Regular, GraphicsUnit.Point);
            dataGridView1.DefaultCellStyle.BackColor = Color.Empty;
            dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = SystemColors.ControlLight;
            dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
            dataGridView1.GridColor = SystemColors.ControlDarkDark;

        }

    }

AnswerRe: Multithread email reader!!! Pin
N a v a n e e t h9-Nov-09 5:29
N a v a n e e t h9-Nov-09 5:29 
QuestionMessage Closed Pin
9-Nov-09 4:28
sima39-Nov-09 4:28 
AnswerRe: love Pin
EliottA9-Nov-09 4:31
EliottA9-Nov-09 4:31 
AnswerMy vote of 1 Pin
Keith Barrow9-Nov-09 4:40
professionalKeith Barrow9-Nov-09 4:40 
AnswerRe: love Pin
EliottA9-Nov-09 4:47
EliottA9-Nov-09 4:47 
GeneralRe: love Pin
Luc Pattyn9-Nov-09 5:02
sitebuilderLuc Pattyn9-Nov-09 5:02 
GeneralRe: love Pin
EliottA9-Nov-09 5:04
EliottA9-Nov-09 5:04 
GeneralRe: love Pin
Christian Graus9-Nov-09 9:17
protectorChristian Graus9-Nov-09 9:17 
Questiondatagridview will crash Pin
reza assar9-Nov-09 4:03
reza assar9-Nov-09 4:03 
AnswerRe: datagridview will crash Pin
EliottA9-Nov-09 4:19
EliottA9-Nov-09 4:19 
GeneralRe: datagridview will crash Pin
reza assar9-Nov-09 18:17
reza assar9-Nov-09 18:17 
AnswerRe: datagridview will crash Pin
konglx sir9-Nov-09 4:29
konglx sir9-Nov-09 4:29 
AnswerRe: datagridview will crash Pin
reza assar9-Jan-10 4:16
reza assar9-Jan-10 4:16 
QuestionGUID Unique identifer theory question Pin
saludalabs9-Nov-09 3:35
saludalabs9-Nov-09 3:35 
AnswerRe: GUID Unique identifer theory question Pin
PIEBALDconsult9-Nov-09 3:44
mvePIEBALDconsult9-Nov-09 3:44 
AnswerRe: GUID Unique identifer theory question Pin
Richard MacCutchan9-Nov-09 3:46
mveRichard MacCutchan9-Nov-09 3:46 
GeneralRe: GUID Unique identifer theory question Pin
saludalabs9-Nov-09 3:51
saludalabs9-Nov-09 3:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.