?
Solved

Connection TimeOut

Posted on 2009-04-16
2
Medium Priority
?
628 Views
Last Modified: 2012-05-06
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
Comment
Question by:man_luck
2 Comments
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 24156793
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
 

Accepted Solution

by:
man_luck earned 0 total points
ID: 24165026
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question