0

可能重复:
如何在 ASP.NET 表单中使用 gmail SMTP

发送邮件时出现异常。- 根据验证程序,远程证书无效。需要解决方案。我的代码是:

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;
            }
        }
4

1 回答 1

1

如评论中所述,您应该为 gmail 添加此内容。

smtpClient.SmtpPort = 587;

更多信息可以在这个线程中找到:How to use gmail SMTP in ASP.NET form

于 2012-04-24T20:52:50.507 回答