Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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
 
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 5-Feb-13 21:27pm
danil33399
Edited 5-Feb-13 21:32pm
(no name)49.6K
v3
Comments
Kishor Deshpande at 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/ at 6-Feb-13 2:33am
   
[moved from direct comment]
danil33 - 24 secs ago
Thanks for reply.Not attaching anything.Session timeout is 15.
danil33 at 6-Feb-13 2:36am
   
Thanks for reply.Not attaching anything.Session timeout is 15.
Sandeep Mewara at 6-Feb-13 2:32am
   
Session timeout or connection timeout?
danil33 at 6-Feb-13 2:32am
   
Thanks for reply.Not attaching anything.Session timeout is 15.
Ankur\m/ at 6-Feb-13 2:34am
   
Use the 'reply' link beside the comment. Commenter doesn't get notified otherwise.
Kishor Deshpande at 6-Feb-13 2:36am
   
Are you using forms authentication??
danil33 at 6-Feb-13 2:54am
   
Yes

<forms loginUrl="~/Account/Login.aspx" timeout="15" />

danil33 at 6-Feb-13 2:55am
   

<forms loginUrl="~/Account/Login.aspx" timeout="15" />

danil33 at 6-Feb-13 2:57am
   
yes forms authentication is using
danil33 at 6-Feb-13 3:51am
   
sorry,see forms authentication
 

<forms loginUrl="~/Account/Login.aspx" timeout="15" />

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

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 265
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2014
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