Click here to Skip to main content
12,688,944 members (31,355 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# 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;
            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;
            return true;

Posted 6-Feb-13 19:31pm
Updated 6-Feb-13 19:51pm
Rate this: bad
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.
Nijel Sabra 7-Feb-13 4:58am
Is that problem related to domain
NetworkCredential cred = new NetworkCredential(mailFrom, mailPassword, smptpServer);
i provided smptpServer="", is it correct?
Nijel Sabra 7-Feb-13 4:59am
mailFrom and mailPassword related to gmail, thats why i gave
Rate this: bad
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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100