Since you are using WebForms, I would recommend rendering your log in the control as a string , and then attach this to MailMessage .
Part of the rendering would look something like this:
public static string GetRenderedHtml(this Control control) { StringBuilder sbHtml = new StringBuilder(); using (StringWriter stringWriter = new StringWriter(sbHtml)) using (HtmlTextWriter textWriter = new HtmlTextWriter(stringWriter)) { control.RenderControl(textWriter); } return sbHtml.ToString(); }
If you have editable controls ( TextBox , DropDownList , etc.), you need to replace them with labels or literals before calling GetRenderedHtml() . See this blog post for a complete example.
Here is an example MSDN for attachments :
// Specify the file to be attached and sent. // This example assumes that a file named Data.xls exists in the // current working directory. string file = "data.xls"; // Create a message and set up the recipients. MailMessage message = new MailMessage( "jane@contoso.com", "ben@contoso.com", "Quarterly data report.", "See the attached spreadsheet."); // Create the file attachment for this e-mail message. Attachment data = new Attachment(file, MediaTypeNames.Application.Octet); // Add time stamp information for the file. ContentDisposition disposition = data.ContentDisposition; disposition.CreationDate = System.IO.File.GetCreationTime(file); disposition.ModificationDate = System.IO.File.GetLastWriteTime(file); disposition.ReadDate = System.IO.File.GetLastAccessTime(file); // Add the file attachment to this e-mail message. message.Attachments.Add(data);
jrummell Feb 07 2018-12-12T00: 00Z
source share