0

Here is my code to send a mail, but I want to send my invoice view in mail.

MessageDetails _msg = new MessageDetails();
_msg.Body = "Your Booking is Accepted";
string userId = null;
if (booking.BookedFor != "0")
{ 
    userId = booking.BookedFor;
}
else
{
    userId = booking.UserId;
}
var code = userName.GetUserNameById(Convert.ToInt16(userId));
_msg.Destination = new string[] { code };
_msg.Subject = "Booking Confirmed";
_service.SendEmail(_msg);

How to send a Invoice View through mail?

slavoo
  • 5,798
  • 64
  • 37
  • 39

3 Answers3

0

Actually you can not send view through email. You need to convert the view to raw html then parse the html at messagebody.

sina_Islam
  • 1,068
  • 12
  • 19
0

If you're using Razor views - I think something like this can help you achieve your goal:

//create a view model 
var path = Server.MapPath("~/Relative/Path/To/YourView.cshtml");
var fileContent = System.IO.File.ReadAllText(path);
var result = Razor.Parse(fileContent, yourViewModel);
_msg.Body = result;
suwik
  • 110
  • 7
0

You can send parameters to the razor view and generate dynamic content very easily

This method is used by me to convert Razor view to HTML

https://stackoverflow.com/a/38322783/5237614

Its easy to generate and style html, very easy to test also

Community
  • 1
  • 1
Arun Prasad E S
  • 9,489
  • 8
  • 74
  • 87