This method accepts an instance of a control inherited from System.Web.UI.Control and renders it to the email body.
This method can be used for inserting a rendered control in a specific place in the email message body.
For example, by calling the following code snippet
DataGrid dg = BuildDataGrid();//a method which returns a DataGrid.
EmailMessage m = new EmailMessage();
m.Body = GetBodyText(); //a method to set the email text
m.AppendControlToBody( dg, "##datagrid_here##");
This method will locate the text: ##datagrid_here##, and replace it with the rendered contents of the DataGrid dg.
[C#]
EmailMessage msg = new EmailMessage( "mail.myCompany.com");
msg.FromAddress = "me@myCompany.com";
msg.To = "You@YourCompany.com";
msg.Subject = "Requested Data";
//build a datagrid
DataGrid dg = new DataGrid();
//have a method called GetDataTable() that builds a datatable from a database.
dg.DataSource = GetDataTable();
dg.DataBind();
//by using some place holder text, we can control where the datagrid is rendered
msg.Body = "the ddatagrid will be after this text<br>##DataGridHere##<br>But before this text.";
msg.AppendControlToBody( dg, "##DataGridHere##" );
msg.Send();
[VB.NET]
Dim msg As New EmailMessage("mail.myCompany.com")
msg.FromAddress = "me@myCompany.com"
msg.To = "You@YourCompany.com"
msg.Subject = "Requested Data"
'build a datagrid
Dim dg As New DataGrid()
'have a method called GetDataTable() that builds a datatable from a database.
dg.DataSource = GetDataTable()
dg.DataBind()
'by using some place holder text, we can control where the datagrid is rendered
msg.Body = "the ddatagrid will be after this text<br>##DataGridHere##<br>But before this text."
msg.AppendControlToBody(dg, "##DataGridHere##")
msg.Send()
EmailMessage Class | aspNetEmail Namespace | EmailMessage.AppendControlToBody Overload List