我正在使用razorengine发送电子邮件。 senden不是问题,但内容只在内容中显示为/ da / Property / Property / Mail / TellAFriendTextMail。
private void SendTellAFriendMail(NotificationTellAFriend mailData)
{
string textmail = this.GetMailAsText(mailData);
string htmlmail = this.GetMailAsHTML(mailData);
MailAddress from = new MailAddress("robot@mail.com", mailData.SenderName);
MailAddress to = new MailAddress(mailData.receiverMail, mailData.SenderName);
using (AlternateView htmlview = this.CreateView(htmlmail, "text/html"))
using (AlternateView textview = this.CreateView(textmail, "text/plain"))
using (MailMessage email = new MailMessage(from, to))
{
email.Subject = string.Format(CultureInfo.InvariantCulture, Resources.Resources._MailSubject, mailData.SenderName);
email.AlternateViews.Add(textview);
email.AlternateViews.Add(htmlview);
email.ReplyToList.Add(new MailAddress(mailData.receiverMail, mailData.SenderName));
using (SmtpClient client = new SmtpClient())
{
client.Send(email);
}
}
}
private string GetMailAsHTML(NotificationTellAFriend mailData)
{
return Razor.Parse(Url.Action("/Property/Mail/TellAFriendTextMail"), mailData);
}
答案 0 :(得分:1)
Razor.Parse
方法的第一个参数不是url,而是要解析的实际Razor内容。所以:
private string GetMailAsHTML(NotificationTellAFriend mailData)
{
var razorTemplateFile = Server.MapPath("~/Property/Mail/TellAFriendTextMail.cshtml");
var razorTemplate = File.ReadAllText(razorTemplateFile);
return Razor.Parse(razorTemplate, mailData);
}