Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
Unable to send the mail using System.Net.mail using following code,always showing session timeout and I am unable to understand what the problem is.Please help

C#
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;
        }
Posted
Updated 5-Feb-13 20:32pm
v3
Comments
Kishor Deshpande 6-Feb-13 2:29am    
What is value of session timeout that you've specified?
Are you attaching any files, may be attachment is taking more time to get uploaded..
Ankur\m/ 6-Feb-13 2:33am    
[moved from direct comment]
danil33 - 24 secs ago
Thanks for reply.Not attaching anything.Session timeout is 15.
danil33 6-Feb-13 2:36am    
Thanks for reply.Not attaching anything.Session timeout is 15.
Sandeep Mewara 6-Feb-13 2:32am    
Session timeout or connection timeout?
danil33 6-Feb-13 2:32am    
Thanks for reply.Not attaching anything.Session timeout is 15.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900