简体   繁体   English

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

[英]send view in email body mvc

I want to send a view in email body in mvc.我想在 mvc 的电子邮件正文中发送一个视图。 please guide how to render view so that it can be sent as html email body.请指导如何呈现视图,以便它可以作为 html 电子邮件正文发送。

thanks,谢谢,

Consider using something like ActionMailer .考虑使用类似ActionMailer 的东西。 You can download it using NuGet .您可以使用NuGet下载它。

string path = ConfigurationManager.AppSettings["ProjectPath"] ;字符串路径 = ConfigurationManager.AppSettings["ProjectPath"] ; string gmailpath = path + "/" + "Driver/VerificedAccount?code=" + root.Result.EmailVerificationCode; 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); var st = EmailclassHtml(sendemail.Email, "Verification-Driver", body);

public string EmailclassHtml(string email, string subjectname, string messgae) { 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;
    }

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

相关问题 使用MVC Razor View发送电子邮件 - Send Email using MVC Razor View 以pdf格式发送html视图,并在mvc中发送电子邮件 - Send a html view as a pdf and email in mvc 如何从 SmtpClient() asp.net 核心 MVC 中的文件夹中发送带有图像(作为 email 的主体)的 email - how to send email with image (as body of the email ) attached form the folder in SmtpClient() asp.net core MVC 在Asp.Net MVC Razor中将HTML视图作为电子邮件附件发送 - Send HTML view as an Email Attachment in Asp.Net MVC Razor asp.net mvc异步发送具有不同主题和正文的多个电子邮件 - asp.net mvc send multiple email with different subject and body asynchronously ReactJs-发送带有电子邮件正文和附件的电子邮件 - ReactJs - Send Email with email body and attachment 如何根据MVC视图中的下拉菜单选择将电子邮件发送到专用电子邮件地址 - How can I send email to dedicated email address based on dropdown selection in MVC view 在 MVC 5 中使用 mailKit 发送电子邮件 - Send an email using mailKit in MVC 5 通过异常在MVC发送电子邮件 - through exception in mvc on send email C#MVC 5将html视图转换为PDF以在Bussness Layer中发送电子邮件附件 - C# MVC 5 Converting html view to PDF to send an email attachment in Bussness Layer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM