[英]MVC4 : Save as html and email it
I know i am asking for information here but seems like a relevant question and i am getting no ideas how to do it . 我知道我在这里询问信息,但似乎是一个相关的问题,我不知道该怎么做。 please help.
请帮忙。
Problem: We have requirements to send an email with a html attachment. 问题:我们要求发送带有html附件的电子邮件。
Sending E-mail part is taken care of as a part of our APT but the problem is with the html attachment. 发送电子邮件部分已作为我们APT的一部分处理,但问题在于html附件。
Requirement: we have to send the current view which is displayed on the UI as a html file. 要求:我们必须发送当前视图,该视图以html文件的形式显示在用户界面上。
How can i get the full html in the controller from the view? 如何从视图中获取控制器中的完整HTML?
Attachment = new AttachmentContract
{
Path = AppSettings.NoticeAttachmentFilePath,
FileName = "filenamehtml",
Content = <<here we want to set that html>>
}
You could try using something like this: 您可以尝试使用以下方法:
https://github.com/smsohan/MvcMailer https://github.com/smsohan/MvcMailer
Found out the solution guys with the help of some other question here's what i am doing 在其他问题的帮助下找到了解决方案的人,这就是我在做什么
Attachment = new AttachmentContract
{
Path = AppSettings.NoticeAttachmentFilePath,
FileName = "filenamehtml",
Content = testmethod()
}
private string TestMethod(ModelData modelData)
{
ViewData.Model = modelData;
StringWriter output;
using (output = new StringWriter())
{
var result = ViewEngines.Engines.FindView(this.ControllerContext, "EmailAttachment", null);
var viewContext = new ViewContext(this.ControllerContext, result.View, this.ViewData, this.ControllerContext.Controller.TempData, output);
result.View.Render(viewContext, output);
result.ViewEngine.ReleaseView(this.ControllerContext, result.View);
}
return output.ToString();
}
Where EmailAttachment is a view i am going to fill in my logic using the same model
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.