在电子邮件正文 MVC 中发送视图

发布于 2024-11-02 01:15:10 字数 74 浏览 1 评论 0原文

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

谢谢,

I want to send a view in email body in mvc.
please guide how to render view so that it can be sent as html email body.

thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦纸 2024-11-09 01:15:10

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

Consider using something like ActionMailer. You can download it using NuGet.

悲凉≈ 2024-11-09 01:15:10

字符串路径 = ConfigurationManager.AppSettings["ProjectPath"] ;
string gmailpath = 路径 + "/" + "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, "验证驱动程序", body);

公共字符串EmailclassHtml(字符串电子邮件,字符串主题名称,字符串消息)
{

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

string path = 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;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文