locked
System.Net.Mail.SmtpException: The operation has timed out. RRS feed

  • Question

  • User2031860760 posted

    hello everyone i am sending two different mails at the same time same page. First mail is going very well but while sending second mail its showing exception System.Net.Mail.SmtpException: The operation has timed out. I am attching my code below.

    string strFrom = "tarun@xx.in";
                    string strTo = user.email;
                    string strSubject = "Thank You For Registering";
                    string strBody = "<html>hi " + user.name + ", <br></br><br></br>You have successfully Registered for the event.<br></br><br></br>Soon we will get back to you.<br></br><br></br>This is auto reply , please do not reply to this mail.<br></br><br></br><br></br>With Thanks & Regards<br></br>Event Organizer</html>";
                    string mailHost = "xxx.yy.in";
    
                    MailMessage msg = new MailMessage();
    
                    msg.From = new System.Net.Mail.MailAddress(strFrom);
                    msg.To.Add(strTo);
                                                   
                    msg.Subject = strSubject;
    
                    msg.Body = strBody;
                    msg.IsBodyHtml = true;
                    ContentType mimeType = new ContentType("text/html");
                    AlternateView alternate = AlternateView.CreateAlternateViewFromString(strBody, mimeType);
                    msg.AlternateViews.Add(alternate);
    
                    SmtpClient mailClient = new SmtpClient(mailHost);
                    mailClient.Send(msg);
    
                       
                        string strFrom1 = "sdf@yy.in";
                        
                        string strSubject1 = "Registration for  Camp 2012 " + user.name;
                        string strBody1 = "hi " + user.name + ". <html><br></br>You have successfully Registered for the event. The details for the participant are given below<br></br><br></br>"
                            + "<br></br>Name: " + user.name
                            + "<br></br>Designation: " + user.designation
                            + "<br></br>Organization: " + user.org_uni
                            + "<br></br>Phone: " + user.phone
                            + "<br></br>Mobile: " + user.mobile
                            + "<br></br>E-mail: " + user.email
                            + "<br></br>Accomodation: " + user.accomodation
                            + "<br></br>Programme: " + prog
                            +"</html>";
                        string mailHost1 = "xxx.yy.in";
    
                        MailMessage msg1 = new MailMessage();
    
                        msg1.From = new System.Net.Mail.MailAddress(strFrom1);
    
                        msg1.Subject = strSubject1;
    
                        if (RadioButton_day1.Checked)
                            //msg.CC.Add("mirap@cdac.in");
                            msg1.To.Add("tarunv@cdac.in");
                        else if (RadioButton_day2.Checked)
                        {
                            if (CheckBox_CFD.Checked || CheckBox_CSM.Checked)
                            {
                                
                                msg1.To.Add("tarun.spicy@gmail.in");
                            }
                            if (CheckBox_SDP.Checked)
                            {
                                
                                msg1.To.Add("direct_tarun@yahoo.co.in");
                            }
                        }
    
    
                        msg1.Body = strBody1;
                        msg1.IsBodyHtml = true;
                        ContentType mimeType1 = new ContentType("text/html");
                        AlternateView alternate1 = AlternateView.CreateAlternateViewFromString(strBody1, mimeType1);
                        msg1.AlternateViews.Add(alternate1);
                        
    
    
                        
                        SmtpClient mailClient1 = new SmtpClient(mailHost1);
                        mailClient1.Send(msg1);
          
                        Response.Redirect("~/html/RegistrationForm_sucess.aspx", false);


    at the bold line i am getting the exception. Help me ASAP. Thnx in advance.

    Monday, July 16, 2012 3:40 AM

Answers

  • User2031860760 posted

    thnx to everyone for giving your time i have solved the problem by myself. The problem is the mail id i have used tarun.spicy@gmail.in....when i change it to .com it starts working. No idea why but its working.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 16, 2012 7:20 AM

All replies

  • User1210476459 posted

    just check the badmail folder, may be it is stuck there due to some reason....

    Monday, July 16, 2012 4:48 AM
  • User-25924017 posted

    hello everyone i am sending two different mails at the same time same page. First mail is going very well but while sending second mail its showing exception System.Net.Mail.SmtpException: The operation has timed out. I am attching my code below.

    string strFrom = "tarun@xx.in";
                    string strTo = user.email;
                    string strSubject = "Thank You For Registering";
                    string strBody = "<html>hi " + user.name + ", <br></br><br></br>You have successfully Registered for the event.<br></br><br></br>Soon we will get back to you.<br></br><br></br>This is auto reply , please do not reply to this mail.<br></br><br></br><br></br>With Thanks & Regards<br></br>Event Organizer</html>";
                    string mailHost = "xxx.yy.in";
    
                    MailMessage msg = new MailMessage();
    
                    msg.From = new System.Net.Mail.MailAddress(strFrom);
                    msg.To.Add(strTo);
                                                   
                    msg.Subject = strSubject;
    
                    msg.Body = strBody;
                    msg.IsBodyHtml = true;
                    ContentType mimeType = new ContentType("text/html");
                    AlternateView alternate = AlternateView.CreateAlternateViewFromString(strBody, mimeType);
                    msg.AlternateViews.Add(alternate);
    
                    SmtpClient mailClient = new SmtpClient(mailHost);
                    mailClient.Send(msg);
    
                       
                        string strFrom1 = "sdf@yy.in";
                        
                        string strSubject1 = "Registration for  Camp 2012 " + user.name;
                        string strBody1 = "hi " + user.name + ". <html><br></br>You have successfully Registered for the event. The details for the participant are given below<br></br><br></br>"
                            + "<br></br>Name: " + user.name
                            + "<br></br>Designation: " + user.designation
                            + "<br></br>Organization: " + user.org_uni
                            + "<br></br>Phone: " + user.phone
                            + "<br></br>Mobile: " + user.mobile
                            + "<br></br>E-mail: " + user.email
                            + "<br></br>Accomodation: " + user.accomodation
                            + "<br></br>Programme: " + prog
                            +"</html>";
                        string mailHost1 = "xxx.yy.in";
    
                        MailMessage msg1 = new MailMessage();
    
                        msg1.From = new System.Net.Mail.MailAddress(strFrom1);
    
                        msg1.Subject = strSubject1;
    
                        if (RadioButton_day1.Checked)
                            //msg.CC.Add("mirap@cdac.in");
                            msg1.To.Add("tarunv@cdac.in");
                        else if (RadioButton_day2.Checked)
                        {
                            if (CheckBox_CFD.Checked || CheckBox_CSM.Checked)
                            {
                                
                                msg1.To.Add("tarun.spicy@gmail.in");
                            }
                            if (CheckBox_SDP.Checked)
                            {
                                
                                msg1.To.Add("direct_tarun@yahoo.co.in");
                            }
                        }
    
    
                        msg1.Body = strBody1;
                        msg1.IsBodyHtml = true;
                        ContentType mimeType1 = new ContentType("text/html");
                        AlternateView alternate1 = AlternateView.CreateAlternateViewFromString(strBody1, mimeType1);
                        msg1.AlternateViews.Add(alternate1);
                        
    
    
                        
                        SmtpClient mailClient1 = new SmtpClient(mailHost1);
                        mailClient1.Send(msg1);
          
                        Response.Redirect("~/html/RegistrationForm_sucess.aspx", false);


    at the bold line i am getting the exception. Help me ASAP. Thnx in advance.

    First of all make it bit more clearner. Dispose SMTP client if it's not in use anymore. (use usign statement or call dispose manully)

    using (SmtpClient mailClient = new SmtpClient(mailHost))  
       
    {
         
    MailMessage msg = new MailMessage();

         
    ...

          mailClient
    .Send(msg);
       
    }
     using (SmtpClient mailClient1 = new SmtpClient(mailHost1))  
       
    {
         
    MailMessage msg1 = new MailMessage();

         
    ...

          mailClient
    .Send(msg1);
       
    }
    If you can make use of one SmtpClient, prefer that.(in this case if your mailhost or server is same)
    Monday, July 16, 2012 5:05 AM
  • User2031860760 posted

    thnx to everyone for giving your time i have solved the problem by myself. The problem is the mail id i have used tarun.spicy@gmail.in....when i change it to .com it starts working. No idea why but its working.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 16, 2012 7:20 AM