I'm using ASP.Net MVC 4 and MVCMailer 4.0 from Nuget. When I create a message and send it to the scaffolded Welcome message everything works fine and I'm able to send the email just fine (the only thing is that its in plain text where as I have html in it)
My problem comes when I use the Contact form to send a message. First let me show you what I have and how I'm using it:
/*UserMailer.cs*/
public virtual MvcMailMessage ContactForm(MailMessage mailmessage)
{
ViewBag.Name = mailmessage.Name;
ViewBag.Body = mailmessage.MessageBody;
return Populate(x =>
{
x.Subject = "Scheduler) " + mailmessage.Subject;
x.ViewName = "Contact Form";
x.To.Add("Hiva@Varyan.com");
});
}
Now on to the View
@*ContactForm.cshtml*@
<h2>ContactForm</h2>
<strong>Name: </strong> @ViewBag.Name <br />
<strong>Message: </strong> @ViewBag.Body
And Lastly the Contact Controller actions that instantiates the mailer and sends the mail
//ContactController.cs
namespace Scheduler.Controllers
{
public class ContactController : Controller
{
//
// GET: /Contact/
private IUserMailer _userMailer = new UserMailer();
public IUserMailer UserMailer
{
get { return _userMailer; }
set { _userMailer = value; }
}
public ActionResult Index()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Index(MailMessage _mailMessage)
{
UserMailer.ContactForm(_mailMessage).Send();
return View();
}
}
}
Just for Completeness I'll include my model as well
//MailMessage.cs
namespace Scheduler.Model
{
public class MailMessage
{
public string Name { get; set; }
public string EmailAddress { get; set; }
public string Subject { get; set; }
public string MessageBody { get; set; }
}
}
ok, so there are multiple issues that I'm having:
I've just started learning ASP.Net MVC and if there are any pointers on how to implement the above correctly would be greatly appreciated.
I'm sorry, I've mistakenly placed a space in the x.ViewName
and since it was really late didn't catch it.