【问题标题】:send view in email body mvc在电子邮件正文 mvc 中发送视图
【发布时间】:2011-08-07 05:18:01
【问题描述】:

我想在 mvc 的电子邮件正文中发送一个视图。 请指导如何呈现视图,以便它可以作为 html 电子邮件正文发送。

谢谢,

【问题讨论】:

    标签: asp.net-mvc email viewresult


    【解决方案1】:

    考虑使用ActionMailer 之类的东西。您可以使用NuGet 下载它。

    【讨论】:

    • 链接已关闭:“该链接在这里没有电源” - 两个链接都不起作用
    【解决方案2】:

    字符串路径 = ConfigurationManager.AppSettings["ProjectPath"] ; string gmailpath = path + "/" + "Driver/VerificedAccount?code=" + root.Result.EmailVerificationCode;

                    var body= "<html><body><p></p><p><a href = "+gmailpath+" > Please click  Verifed  Account   </a></p></body></html> ";
    

    var st = EmailclassHtml(sendemail.Email, "Verification-Driver", body);

    public string EmailclassHtml(string email, string subjectname, string messgae) {

            string ownemail = ConfigurationManager.AppSettings["SenderEmail"];
            string ownname = ConfigurationManager.AppSettings["SenderName"];
            string returnmessage = "success";
    
            var senderEmail = new MailAddress(ownemail, ownname);
            var receiverEmail = new MailAddress(email, "Receiver");
            var password = ConfigurationManager.AppSettings["SenderPassword"];
            var sub = subjectname;
            var body = messgae;
    
            var smtp = new SmtpClient
            {
                Host = "smtp.gmail.com",
                Port = 587,
    
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = true,
                Credentials = new NetworkCredential(senderEmail.Address, password)
    
            };
            using (var mess = new MailMessage(senderEmail, receiverEmail)
            {
                Subject = sub,
                Body = body,
                IsBodyHtml = true
            })
    
                try
                {
                    smtp.Send(mess);
                    return returnmessage;
                }
                catch (Exception)
                {
                    returnmessage = "fail";
    
                }
            return returnmessage;
        }
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-16
    • 2011-02-14
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    相关资源
    最近更新 更多