• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 644
  • Last Modified:

Connection TimeOut

I have a automatic mail sending program, in which i have to send more than 1000 mails at once. but my code fails after 30 mails. I received a error "connection time out". Can anybody help me..
0
man_luck
Asked:
man_luck
1 Solution
 
angus_young_acdcCommented:
Where are you setting the length of the time out condition?  Would need to see some code, but extending that would take away the error
0
 
man_luckAuthor Commented:
I m not setting any time out connection. here is the part of code, hope i'll get something from your side.
Thanks much..
private void btnSend_Click(object sender, EventArgs e)
        {
            if (txtMailID.Text != "")
            {
                try
                {
                    bool check = EmailAddressCheck(txtMailID.Text.ToString().Trim());
                    if (check)
                    {
                        countDays = RegistryValue();
                        if (countDays == 0)
                        {
                            DialogResult result = new DialogResult();
                            result = MessageBox.Show("Licence of the product has been expired. Please register to continue...", "Licence Expire", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                            if (result == DialogResult.Cancel) { this.Close(); }
                            else
                            {
                                System.Diagnostics.Process.Start("iexplore.exe", "http://www.cogniscient.org");
                                this.Close();
                            }
                        }
                        else
                        {                          
                            lblSts.Visible = true;
                            progBar.Visible = true;
                            //CancelButton.DialogResult = System.Windows.Forms.DialogResult."Are you sure?";
 
                            DAL dalExpDate = new DAL();
                            Hashtable htExpDate = new Hashtable();
                            htExpDate.Add("INSTALL_DATE", DateTime.Now.ToShortDateString());
                            string text = System.IO.File.ReadAllText(@"C:\Source.txt");
                            StreamReader sr = new StreamReader(@"C:\Source.txt");
                            strConn = Read(@"C:\Source.txt");
                            //string strReturn = dalExpDate.data_procExpDate("AUTOMATIC_MAIL", htExpDate, strConn);
                            DAL dalProgram = new DAL();
                            Hashtable htInvoice = new Hashtable();
                            htInvoice.Add("company_no", "magpemil");
                            htInvoice.Add("company_locn", "kundli");
                            htInvoice.Add("cust_group", "");
                            htInvoice.Add("cust_no", "");
                            htInvoice.Add("so_locn", "");
                            htInvoice.Add("languageid", "1");
                            //htInvoice.Add("to_date", "03/17/2007");
                            //htInvoice.Add("due_dt", "03/17/2008");
                            //DataTable dt = dalProgram.select_proc("getEmpMail");
 
                            //DataTable dt = dalProgram.select_proc("ar_rep_inv_over_due_test", htInvoice, strConn);
                            DataTable dt = dalProgram.select_proc("ar_rep_rec_status_test", htInvoice, strConn);
                            string strEmail = ""; int idx = 0;
                            foreach (DataRow dr in dt.Rows)
                            {
 
                                strEmail = strEmail + ";" + dt.Rows[idx]["telex_no"].ToString();
                                
                                idx = idx + 1;
                            }
 
                            mailSent objSendMail;
                            MailMessage mailMsg;
                            string split = ";";
                            int total = 0;
                            string[] toList = strEmail.Trim().Split(split.ToCharArray());
                            //int index = 0;
                            //DataTable updatedDT = dt;
                            //updatedDT.Select();
                            rowCount = dt.Rows.Count;
                            colCount = dt.Columns.Count;
                            alColName = new ArrayList();
                            for (int j = 0; j < dt.Columns.Count; j++)
                            {
                                if (dt.Columns[j].ToString() != "email_id")
                                {
                                    alColName.Add(dt.Columns[j]);
                                }
                            }
                            progBar.Minimum = 0;
                            progBar.Maximum = dt.Rows.Count;
                            for (int i = 1; i < dt.Rows.Count; i++)
                            {
                                //mailSent[] 
 
                                //-------------
 
                                
                                objSendMail = new mailSent();
                                //MailMessage[] 
                                mailMsg = new MailMessage();
                                //objSendMail[i] = new mailSent();
                                //mailMsg[i] = new MailMessage();
                                mailMsg.From = new MailAddress(txtMailID.Text.ToString().Trim());
                                mailMsg.To.Add(toList[i].Trim());
 
                                // mailMsg.To = (MailAddressCollection)toList[i].Trim();
                                // mailMsg.To.Add("amit.singh@cogniscient.org");
                                mailMsg.Subject = "Test Mail to " + toList[i].Trim();
                                mailMsg.SubjectEncoding = Encoding.UTF8;
 
                                mailMsg.Body = (string)objSendMail.messageBody(dt.Rows[i],alColName);
                                mailMsg.BodyEncoding = Encoding.UTF8;
                                mailMsg.IsBodyHtml = true;
                                //objSendMail[i].SentMail(mailMsg);
                                objSendMail.SentMail(mailMsg);
                                //index++; 
                                objSendMail = null;
                                mailMsg = null;
                                total += 1;
                                progBar.Value = total;
                                lblSts.Text = total + " of " + progBar.Maximum + " email have been sent successfully...";
                                Application.DoEvents();
                            }
                            MessageBox.Show("Emails sent successfully", "Sucess..");
                        }
 
                    }
                    else
                    {
                        MessageBox.Show("E-MailId is not in correct format.Please enter a valid E-MailId.", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        txtMailID.Focus();
                    }
                }
                catch (Exception ex)
                { MessageBox.Show("There is a problem : " + ex.Message, "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            }
            else
            {
                MessageBox.Show("Please enter an  E-mailID", "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error);
 
                txtMailID.Focus();
            }
        }
 
 
        public class mailSent
        {
            public string messageBody(DataRow drPaymentDue,ArrayList al)
            {
                //strExpr = "OrderDate >= '01.03.1998' AND OrderDate <= '31.03.1998'";
                //dtPaymentDue = (DataTable)dtPaymentDue.Select("due_dt >= '03/17/2009' ", "cust_no ASC");
                //drPaymentDue[""];
                string message = "";
                // for (int i = 0; i < dtPaymentDue.Rows.Count; i++)
                // {
                message = "<html><head><body>Dear Customer,<br>Some payments are Pending in your accounts. Kindly release of the same.<br>Details of payments are given below:";
                message = message + "<br><br><br><table border='0'><tr>";
                for (int i = 0; i < al.Count; i++)
                {
                    message = message + "<td valign='top'>" + al[i].ToString() + "</td>";
                } 
                
                message = message + "</tr><tr>";
                for (int j = 0; j <al.Count  ; j++)
                {
                    if (drPaymentDue[j]==drPaymentDue["email_id"])
                    {
                        
                    }
                    else
                    {
                        message = message + "<td valign='top'>" + drPaymentDue[j].ToString() + "</td>";
                    }
                   
                }
                message = message + "</tr></table>";
                message = message + "<br><b>Thanks,<br>Cogniscient Business Solutions Pvt. Ltd.</b><br>B-49 Sec-63<br>Noida,<br>Ph-0120-242556</body></head></html>";
                // }
 
                return message;
            }
 
            public void SentMail(MailMessage mail)
            {
                SmtpClient client = new SmtpClient();
                client.Host = "216.12.208.202";
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.Send(mail);
                //client.Port = 25; 
                //client.Timeout = 0; 
                //client.UseDefaultCredentials = true;
                // string Uid= System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
                //string pwd = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();
 
                //client.Credentials = new NetworkCredential("amrita.gupta@cogniscient.org", "cogni");
 
                //Application.Exit();
                // Form1 frm = frm.Close(); 
                //
            }
        }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now