繁体   English   中英

c#mvc确认邮件

[英]c# mvc confirmation email

我正在尝试向新注册用户发送带有链接(代码)的确认电子邮件,以确认他们的电子邮件,这是我正在使用的代码,有人看到它有什么问题吗? 我使用来自托管的凭据,它们在其他方法上正常工作。

public class Cls_SendMail
{
    public Cls_SendMail(string mailid, string message, string subject)
    {
        try
        {
            MailMessage objmail = new MailMessage();
            objmail.To.Add(mailid);
            objmail.From = new MailAddress(ConfigurationManager.AppSettings["FROMEMAIL"].ToString());
            objmail.Subject = subject;
            string Body;
            Body = message;
            objmail.Body = Body;
            objmail.IsBodyHtml = true;

            SmtpClient smtp = new SmtpClient();
            smtp.UseDefaultCredentials = false;
            smtp.EnableSsl = false;
            smtp.Host = "mail.host.com";
            smtp.Port = 587; // 465; //Gmail works on this port
            smtp.Timeout = 100000;
            smtp.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["FROMEMAIL"], ConfigurationManager.AppSettings["FROMPWD"]);
            smtp.Send(objmail);
        }
        catch (Exception)
        {

        }
    }
}


 var Token = (from p in context.webpages_Memberships where p.UserId == model.Id select p.ConfirmationToken).FirstOrDefault();
            var resetLink = "<a href='" + Url.Action("ConfirmAccount", "SignUp", new { un = model.Id, rt = Token }, "http") + "' style='color: #28BDF2;'>"+confirm+"</a>";

            string csspath = "http://localhost:50467/EmailHTML/stylesheets/email.css";
            string readFile = reader.ReadToEnd();
            string myString = "";
            UsersContext dbcontext = new UsersContext();
            var username = string.Empty;
            var user = dbcontext.UserProfiles.Find(model.Id);
            if (user!=null)
            {
                username = user.UserName;
            }
            myString = readFile;
            myString = myString.Replace("%{#{CssPath}#}%", csspath);
            myString = myString.Replace("%{#{Name}#}%", model.FirstName);
            myString = myString.Replace("%{#{UserName}#}%", username);
            myString = myString.Replace("%{#{ConfirmLink}#}%", resetLink);
            string subject = acountconfirm;
            string body = myString;
            try
            {
                //call for send mail
                Cls_SendMail mail = new Cls_SendMail(model.Email, body, subject);
                TempData["Message"] = Resource.mailhassent;
            }
            catch (Exception )
            {
                TempData["Message"] = Resource.Erroroccurredwhilesendingemail;
            }

所以经过几个小时的思考,我ve realized i haven在 web.config 中设置凭据

解决方案:检查 webconfig。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM