1

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

谢谢,

4

2 回答 2

3

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

于 2011-04-18T01:24:48.600 回答
0

字符串路径 = 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);

公共字符串EmailclassHtml(字符串电子邮件,字符串主题名,字符串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;
    }
于 2021-02-23T10:49:09.607 回答