Email view not found for 'model' in Postal.MVC

351 views Asked by At

I am using Postal.MVC5 in my ASP MVC5 project. Initially i had my smtp configuration in web.config so this piece of code was working just fine and was able to send email successfully.

public async Task<ActionResult>SendEmail(EmployeeViewModel emailModel)
{
  string _errorMessage;

  emailModel.To = "[email protected]";
  emailModel.Subject = "Test Subject";
  emailModel.Message = "Test Message";

  await emailModel.SendAsync();

  return Json(new {ErrorMessage = _errorMessage});
}

Now, i need to setup Smtpclient during runtime and followed steps shown in this stackoverflow post: How to Set SMTP Client in POSTAL MVC not in WEB.Config

public async Task<ActionResult>SendEmail(EmployeeEmailViewModel emailModel)
{
  string _errorMessage;

  emailModel.To = "[email protected]";
  emailModel.Subject = "Test Subject";
  emailModel.Message = "Test Message";

  //new code
  SmtpClient client = new SmtpClient("smtp.test.com");
  client.UseDefaultCredentials = false;
  client.Credentials = new NetworkCredential("secretId", "notSecretPassword");
  client.DeliveryMethod = SmtpDeliveryMethod.Network;
  client.Port = 111;
  client.EnableSsl = true;

  Postal.EmailService emailService = new EmailService(new ViewEngineCollection(), () => client);
  await emailService.SendAsync(emailModel);

  return Json(new {ErrorMessage = _errorMessage});
}

Now this code throws an error something like this: System.Exception: Email view not found for EmployeeEmailViewModel. Locations searched: at Postal.EmailViewRenderer.CreateView(String viewName, ControllerContext controllerContext) at Postal.EmailViewRenderer.Render(Email email, String viewName)

I do have 'EmployeeEmailViewModel' view in ~/Views/Emails/EmployeeEmailViewModel.cshtml .

Any idea why i am getting this error message or how i can resolve it? Thanks Sanjeev

0

There are 0 answers