0

Possible Duplicate:
How to use gmail SMTP in ASP.NET form

getting exception while sending mail. -The remote certificate is invalid according to the validation procedure. Need solution. My Code is :

public bool mailSender(string toMailId, string uniqueGuid)
        {
            try
            {
                SmtpClient smtpClient = new SmtpClient();
                string linkForConfirm = "orderConfirmation.aspx?id=" + uniqueGuid;
                string Subject = "Shiv Cart Grocery Shop Confirmation";
                string body = " <div style='width:700px; margin:0 auto;'><div style='background-color:#800000; width:700px'>";
                body += "</div><div><h2>Shiv Cart Grocery Shop</h2><h3 style='color:#0099FF; width:700px'> Click Below To Confirm Your Order</h3>";
                body += "<a href='" + linkForConfirm+ "' id='a' ></a></div></div>";
                MailAddress fromMailAddress = new MailAddress("mail@sumedhasoftech.com", "Shiv Cart");
                MailAddress toMailAddress = new MailAddress(toMailId);
                MailMessage mail = new MailMessage(fromMailAddress, toMailAddress);
                mail.Subject = Subject;
                mail.Body = body;
                mail.IsBodyHtml = true;
                smtpClient.Host = "smtp.gmail.com";
                smtpClient.Credentials = new System.Net.NetworkCredential(WebConfigurationManager.AppSettings["MailSenderUserName"].ToString(), WebConfigurationManager.AppSettings["MailSenderPass"].ToString());
                smtpClient.EnableSsl = true;
                smtpClient.Send(mail);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Community
  • 1
  • 1
Ankush Jain
  • 71
  • 2
  • 9

1 Answers1

1

As noted in the comments, you should add this for gmail.

smtpClient.SmtpPort = 587;

And further information can be found in this thread: How to use gmail SMTP in ASP.NET form

Community
  • 1
  • 1
Eric Falsken
  • 4,796
  • 3
  • 28
  • 46