Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public class SendMailerController : Controller
  {
      //
      // GET: /SendMailer/
      public ActionResult Index()
      {
          return View();
      }
      [HttpPost]
      public ViewResult Index(SendMail.Models.MailModel _objModelMail)
     {
          if (ModelState.IsValid)
          {
              MailMessage mail = new MailMessage();
              mail.To.Add(_objModelMail.To);
              mail.From = new MailAddress(_objModelMail.From);
              mail.Subject = _objModelMail.Subject;
              string Body = _objModelMail.Body;
              mail.Body = Body;
              mail.IsBodyHtml = true;
              SmtpClient smtp = new SmtpClient();
              smtp.Host = "smtp.gmail.com";
              smtp.Port = 587;
              smtp.UseDefaultCredentials = false;
              smtp.Credentials = new System.Net.NetworkCredential
              ("username", "password");// Enter seders User name and password
              smtp.EnableSsl = true;
              smtp.Send(mail);
              return View("Index", _objModelMail);
          }
          else
          {
              return View();
          }
      }
  }


What I have tried:

hi frnds,

I am a Beginner in Asp.net Mvc i have one doubt over here..i am trying to send mail to Particular user..the mail has send Properly.but i need to send some different design and i Create some Table Structures also to the user.so how can i done this if its Possible create Separate View for Email...?

if you know this Please share your Code or share some link whatever it is Please help for this .
Posted
Updated 18-Apr-16 2:40am

1 solution

Hello,

You need to utilize the Razor parsing here. First of all create a razor view (an email template ".cshtml").
Then use the Razor parsing, passing the viewmodel with the properties and then render that as Email HTML template and send.
Please follow the below link:
Render Email Templates Using Razor Engine[^]

Nady Blog: Asp.Net MVC Razor Email Template[^]

The second link is not formatted properly, but still you can refer.
Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900