# How to send the output of a web control through mail

For this post am assuming that the SMPT server is configured. (To send Emails using your Gmail Account check this post) We can capture the output of most of the control using their Render Control method. After that you can send the output of the control through a mail. Here is the code for
private string EmailControl(Control ctrl)
{
//Get the output of the control
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);
HtmlTextWriter tw = new HtmlTextWriter(sw);
ctrl.RenderControl(tw);
return sb.ToString();
}
This function returns you the output of any control that is provided. You can use this output as the body of the mailmessage class and send the output of the control through mail.
Reactions