C# 单击URL时页面未打开 private string sendmail(string emailId,string userID) { 尝试 { userID=加密(userID); MailMessage mail=新的MailMessage(); mail.To.Add(emailId); mail.From=新邮件地址(“”); //mail.Subject=“您的帐户密码”+emailId; 字符串userMessage=”http://localhost/LoginWithSession/ResetPassword“+用户ID; userMessage=userMessage+“用户Id:”+emailId; //userMessage=userMessage+“密码剑:”+密码; string Body=“请单击链接重置密码:“+userMessage+”谢谢”; mail.Body=Body; mail.IsBodyHtml=true; SmtpClient smtp=新SmtpClient(); smtp.Host=“smtp.gmail.com”;//gmail的smtp服务器地址 smtp.Port=587; smtp.Credentials=新系统.Net.NetworkCredential(“harianasaif@gmail.com“,”测试“); //用于身份验证的Smtp电子邮件ID和密码 smtp.EnableSsl=true; smtp.发送(邮件); 返回用户消息; } 捕获(例外情况除外) { 返回“错误………”+ex; } }

C# 单击URL时页面未打开 private string sendmail(string emailId,string userID) { 尝试 { userID=加密(userID); MailMessage mail=新的MailMessage(); mail.To.Add(emailId); mail.From=新邮件地址(“”); //mail.Subject=“您的帐户密码”+emailId; 字符串userMessage=”http://localhost/LoginWithSession/ResetPassword“+用户ID; userMessage=userMessage+“用户Id:”+emailId; //userMessage=userMessage+“密码剑:”+密码; string Body=“请单击链接重置密码:“+userMessage+”谢谢”; mail.Body=Body; mail.IsBodyHtml=true; SmtpClient smtp=新SmtpClient(); smtp.Host=“smtp.gmail.com”;//gmail的smtp服务器地址 smtp.Port=587; smtp.Credentials=新系统.Net.NetworkCredential(“harianasaif@gmail.com“,”测试“); //用于身份验证的Smtp电子邮件ID和密码 smtp.EnableSsl=true; smtp.发送(邮件); 返回用户消息; } 捕获(例外情况除外) { 返回“错误………”+ex; } },c#,asp.net-mvc,C#,Asp.net Mvc,**一,。这是我发送电子邮件的代码 问题是我无法打开重置页面时,点击网址 我还创建了虚拟目录** 请检查这个 在这里您需要添加”; //userMessage=userMessage+“密码剑:”+密码; string Body=“请单击链接重置密码:“+userMessage+”谢谢”; mail.Body=Body; mail.IsBodyHtml=true; SmtpClient smtp=新SmtpClient(); smtp.Host=“smtp.gmail.com”;//gmail的

**一,。这是我发送电子邮件的代码

  • 问题是我无法打开重置页面时,点击网址

  • 我还创建了虚拟目录**

  • 请检查这个 在这里您需要添加
    ”;
    //userMessage=userMessage+“
    密码剑:”+密码; string Body=“

    请单击链接重置密码:

    “+userMessage+”

    谢谢”; mail.Body=Body; mail.IsBodyHtml=true; SmtpClient smtp=新SmtpClient(); smtp.Host=“smtp.gmail.com”;//gmail的smtp服务器地址 smtp.Port=587; smtp.Credentials=新系统.Net.NetworkCredential(); //用于身份验证的Smtp电子邮件ID和密码 smtp.EnableSsl=true; smtp.发送(邮件); 返回用户消息; } 捕获(例外情况除外) { 返回“错误………”+ex; } }
    应该是““+userID。我想你错过了/错过了URL。你不需要在链接周围加个标签来确保它是作为链接处理的吗?在那封电子邮件中没有链接,所以没有什么可以先点击第一件事-不要写你自己的密码重置代码。不要编写自己的身份验证代码。ASP.NET MVC已经包含了一种安全的身份验证机制,其中包括密码重置秒,HTML电子邮件仍然是HTML文档,电子邮件客户端远不如浏览器宽容。如果您想在该文档中添加链接,则需要添加一个
    标记,就像其他页面一样。出于明显的安全原因,电子邮件客户端不会自动将纯文本转换为链接。除非答案明显,否则纯代码答案没有帮助。这有助于回答这个问题吗?这与原始代码有何不同?
    标签在哪里?这不会比原始代码更好。电子邮件客户端不会像对待HTML正文中的URL一样对待文本,就好像它是一个
    ,它不起作用,因为发送电子邮件时链接会消失。
    private string sendEmail(string emailId,string userID)
            {
                try
                {               
                    userID = Encrypt(userID);
                    MailMessage mail = new MailMessage();
                    mail.To.Add(emailId);
                    mail.From = new MailAddress("");
                    //mail.Subject = "Your password for account " + emailId;
                    string userMessage = "http://localhost/LoginWithSession/ResetPassword" + userID;
    
                    userMessage = userMessage + "<br/><b>User Id:</b> " + emailId;
                    //userMessage = userMessage + "<br/><b>Passsword: </b>" + password;
    
                    string Body = "<br/><br/>Please  click on link to reset your password:<br/></br> " + userMessage + "<br/><br/>Thanks";
                    mail.Body = Body;
                    mail.IsBodyHtml = true;
    
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host = "smtp.gmail.com"; //SMTP Server Address of gmail
                    smtp.Port = 587;
                    smtp.Credentials = new System.Net.NetworkCredential("harianasaif@gmail.com", "test");
                    // Smtp Email ID and Password For authentication
                    smtp.EnableSsl = true;
                    smtp.Send(mail);
                    return userMessage;
                }
                catch (Exception ex)
                {
                    return "Error............" + ex;
                }
    
            }
    
    //Create one function for getting URL run time like localhost or any domain name 
    public string GetUrl()
    {
       var request = Request;
       return string.Format("{0}://{1}{2}", request.Url.Scheme, request.Url.Authority, (new System.Web.Mvc.UrlHelper(request.RequestContext)).Content("~"));
    }
    
    private string sendEmail(string emailId,string userID)
    {
        try
        {               
            userID = Encrypt(userID);
            MailMessage mail = new MailMessage();
            mail.To.Add(emailId);
            mail.From = new MailAddress("");
            //mail.Subject = "Your password for account " + emailId;
            string userMessage = string.Concat("<a href='",GetUrl(), "LoginWithSession/ResetPassword/", userID,"'>");
    
            userMessage = userMessage + "<br/><b>User Id:</b> " + emailId+"</a>";
            //userMessage = userMessage + "<br/><b>Passsword: </b>" + password;
    
            string Body = "<br/><br/>Please  click on link to reset your password:<br/></br> " + userMessage + "<br/><br/>Thanks";
            mail.Body = Body;
            mail.IsBodyHtml = true;
    
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com"; //SMTP Server Address of gmail
            smtp.Port = 587;
            smtp.Credentials = new System.Net.NetworkCredential();
            // Smtp Email ID and Password For authentication
            smtp.EnableSsl = true;
            smtp.Send(mail);
            return userMessage;
        }
        catch (Exception ex)
        {
            return "Error............" + ex;
        }
    
    }