1

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,

Jeff
  • 21,744
  • 6
  • 51
  • 55
Saboor Awan
  • 1,567
  • 4
  • 24
  • 37

2 Answers2

3

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

Sean Chase
  • 1,139
  • 1
  • 15
  • 23
0

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;
    }
  • 1
    Please edit your question to include some description to your code – William Baker Morrison Feb 23 '21 at 11:26
  • Please check out the [formatting help page](https://stackoverflow.com/editing-help) to improve the formatting in your answer, and also check out [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) to improve your answer. – costaparas Feb 24 '21 at 11:39