Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
While sending mail using my following code, error occured "The operation has timed out.", but am not using any attachment and i make it as null.The code is given. Can anyone help me?
 

public bool SendEmail(string pTo, List<string> ccList, string pSubject, string pBody, string pAttachmentPath, string name)
        {
 
            string mailFrom = System.Web.Configuration.WebConfigurationManager.AppSettings["Email"];
            string mailPassword = System.Web.Configuration.WebConfigurationManager.AppSettings["Password"];
            string smptpServer = System.Web.Configuration.WebConfigurationManager.AppSettings["SmtpServer"];
            string smptpServerPort = System.Web.Configuration.WebConfigurationManager.AppSettings["SmtpServerPort"];
            NetworkCredential cred = new NetworkCredential(mailFrom, mailPassword, smptpServer);
            MailMessage myMail = new MailMessage();
            myMail.From = new MailAddress(mailFrom, "hai");
            myMail.To.Add(new MailAddress(pTo, name));
            myMail.IsBodyHtml = true;
            myMail.Subject = pSubject;
            myMail.Body = pBody;
            myMail.BodyEncoding = System.Text.Encoding.UTF8;
            myMail.Priority = MailPriority.High;
            if (ccList != null)
            {
                if (ccList.Count > 0)
                {
                    string ccEmailIdList = "";
                    foreach (string ccEmailId in ccList)
                    {
                        if (ccEmailIdList != "")
                        {
                            ccEmailIdList += ";";
                        }
                        ccEmailIdList += ccEmailId;
                    }
                    myMail.CC.Add(ccEmailIdList);
                }
            }
            if (pAttachmentPath.Trim() != "")
            {
 
                myMail.Attachments.Add(new Attachment(pAttachmentPath));
            }
            SmtpClient client = new SmtpClient(smptpServer, int.Parse(smptpServerPort));
            client.Credentials = cred;
            client.UseDefaultCredentials = false;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = true;
            client.Send(myMail);
            return true;
        }
Thanks
Nijel
Posted 6-Feb-13 18:31pm
Edited 6-Feb-13 18:51pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Check your email connection settings (in configuration file) and make sure these are correct.
Try debugging your source code to further ensure that you are connecting with the right credentials to the right server.
  Permalink  
Comments
Nijel Sabra at 7-Feb-13 4:58am
   
Is that problem related to domain
NetworkCredential cred = new NetworkCredential(mailFrom, mailPassword, smptpServer);
i provided smptpServer="smtp.gmail.com", is it correct?
Nijel Sabra at 7-Feb-13 4:59am
   
mailFrom and mailPassword related to gmail, thats why i gave smtp.gmail.com
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Check Link given below:
Forum post
Says that Send will try to send mail to mail ids, if any of the id is incorrect, it will keep trying sending mail which will result in operation time out error.
Make sure that you've mentioned email ids correctly.
Have try catch on your send method.
Link: Answer on code project
Thanks.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 248
1 Maciej Los 210
2 Sergey Alexandrovich Kryukov 160
3 Peter Leow 155
4 George Jonsson 135


Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid