ASP.NET - Submitting form details in Email - Asked By Naresh Kumar on 12-Jul-11 08:47 AM

Hi All,

Is there any possiblity to send an email to Users which contains the HTML controls? Then the Users enters there details and submit. I need to capture these details and save.

I donot know whether it is possible or not. Please guide me in this.

Appreciate your help.
Jitendra Faye replied to Naresh Kumar on 12-Jul-11 08:54 AM

Follow these steps-

1. Create a Web application or add a new aspx page to your web application.
2. Place controls as required. for example, screen below-

3. Design of ASPX page is:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head runat="server">

<title>Web Mail</title>













<form id="form1" runat="server">

<table style="background-color: Window; border: solid 1px blue; width: 500px; border-color: Blue;">


<td colspan="2" style="text-align: center; background-color: Blue; font: bold, 15px;

color: White;">

<asp:Label ID="lblTitle" runat="server" Text="Send Your Feedback"></asp:Label>




<td class="width100">

<asp:Label ID="lblName" runat="server" Text="Your Name:"></asp:Label>


<td class="width200">

<asp:TextBox ID="txtName" runat="server"></asp:TextBox>




<td class="width100">

<asp:Label ID="lblEmail" runat="server" Text="Your E-mail:"></asp:Label>


<td class="width200">

<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>




<td colspan="2" style="width: 300px">

<asp:TextBox ID="txtMailBody" runat="server" TextMode="MultiLine" Rows="10" Width="478px"></asp:TextBox>




<td style="text-align: center;">

<asp:Button ID="btnSend" runat="server" Text="Send" OnClick="btnSend_Click" />


<td style="text-align: center;">

<asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="btnReset_Click" />





<asp:Label ID="lblStatus" runat="server" Width="81px"></asp:Label>







4. Now change the Code behind of .aspx.cs as below:


using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Net.Mail;

public partial class _Default : System.Web.UI.Page


string strUserName = "";

string strUserEmail = "";

string strSubject = "";

string strUserMailBody = "";

protected void Page_Load(object sender, EventArgs e)



protected void btnReset_Click(object sender, EventArgs e)




private void clearFields()


txtEmail.Text = string.Empty;

txtName.Text = string.Empty;

txtMailBody.Text = string.Empty;

lblStatus.Text = string.Empty;


protected void btnSend_Click(object sender, EventArgs e)


strUserName = txtName.Text;

strUserEmail = txtEmail.Text.ToString().Trim();

strSubject = "User Feedback";

strUserMailBody = txtMailBody.Text;

sendMail(strUserName, strUserEmail, strSubject, strUserMailBody);


private void sendMail(string uname, string umail, string sub, string mailbody)


string SMTPServerName = "SLONP143EEX1";

SmtpClient client = new SmtpClient(SMTPServerName);

MailMessage message = new MailMessage();



MailAddress fromAddress = new MailAddress(umail, uname);

message.From = fromAddress;

message.Subject = sub;

message.Body = mailbody;

message.To.Add(;   /*Site admin email*/



lblStatus.Text = "Mail sent successfully.";


catch(Exception ex)


lblStatus.Text = "Error : " + ex.ToString();




5. Build and Run.
6. Test by sending mail.

Hope this will help you.

dipa ahuja replied to Naresh Kumar on 12-Jul-11 08:55 AM
Yes you can attatch html control in email

protected void Button1_Click(object sender, EventArgs e)
    string toEmailAddress = "";
    string GmailId = "";
    string password = "xxx";
    string bodyMsg = "<html><body>Enter Name<input type='text'/></body></html>";
    MailMessage mail = new MailMessage();
    mail.From = new MailAddress(GmailId);
    mail.Subject = txtSubject.Text;
    mail.Body = bodyMsg;
    mail.IsBodyHtml = true;
    //OR attatch from your computer
    //  mail.Attachments.Add(new Attachment("path of word document"));
    SmtpClient smtp = new SmtpClient("");
    smtp.EnableSsl = true;
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new System.Net.NetworkCredential(GmailId, password);
Reena Jain replied to Naresh Kumar on 12-Jul-11 09:47 AM

here are two good links for help

Hope  this  will help you
Radhika roy replied to Naresh Kumar on 12-Jul-11 10:08 AM
Follow these steps-

1. Add the below code between the <appSettings> Add the below with your IP  </appSettings> tags. Your resultant    code looks like this


<add key="SmtpServer" value="<Your SMTP IP>"/>


2. Use this code

Private Sub SendClick()
      Dim mailMsg As New MailMessage
        mailMsg.To = "<tomailid>"
        mailMsg.From = "<frommailid>"
        'mailMsg.BodyFormat = MailFormat.Text 'optional for sending text in body
        mailMsg.BodyFormat = MailFormat.Html
        mailMsg.Subject = "Statistics Report"
        mailMsg.Body = "<html><body><Table><tr><td>Hi,</td></tr><tr><td>Details of the Statistics :</td></tr></Table></body></html><html><body>" & "sometext" & _
        "</body></html><html><body><Table><tr><td> </td></tr><tr><td>NOTE: This is an automated mail. Please, do not reply.</td></tr>" & _
        "<tr><td>*Green coloured rows indicates temporary demos</td></tr>" & _
        "<tr><td>**All statistics are based on the page naming conventions Eg., 22_10_2005_</td></tr>" & _
        "<tr><td> </td></tr><tr><td>Regards,</td></tr><tr><td>some text,</td></tr><tr><td>some text,</td></tr>" & _
        "<tr><td> Some text </td></tr></table></body></html>" 
        SmtpMail.SmtpServer = ConfigurationSettings.AppSettings("SmtpServer")
        'xm.InnerHtml = "Your message has been sent"
      Catch ex As Exception
      End Try
    End Sub

Hope this will help you.
Naresh Kumar replied to dipa ahuja on 12-Jul-11 11:05 AM
Thanks for your reply.

I need to submit the Form from Email and capture the submitted details.

I have tried with Gmail but while clicking on submit button in the email I am getting message "You are submitting information to external page! Are you sure?"

This will open the page and I am able to capture the details. when user clicks on the button it is opening the page and processing. But user should not require the page where I am capturing. Below is the code:

string toEmailAddress = "";

string GmailId = "";

string password = "XXXXXX";

string bodyMsg = "<html><head></head><body><form action='http://ServerName/Default2.aspx' id='frmget' method='GET'><p>Your Full Name?<br /><input type='text' name= 'txtName' runat='server'/><br /><input type='submit'></p></form></body></html>";

MailMessage mail = new MailMessage();


mail.From = new MailAddress(GmailId);

mail.Subject = "Hello";

mail.Body = bodyMsg;

mail.IsBodyHtml = true;

//OR attatch from your computer

// mail.Attachments.Add(new Attachment("path of word document"));

SmtpClient smtp = new SmtpClient("");

smtp.EnableSsl = true;

smtp.UseDefaultCredentials = false;

smtp.Credentials = new System.Net.NetworkCredential(GmailId, password);




Page Default2 should not be opened for the users, I need to capture in this way.

Any suggestions... Please guide me...

Thanks in advance.

dipa ahuja replied to Naresh Kumar on 12-Jul-11 11:47 AM
its somewhat tough and odd.. i think you should just give a url of form which contain the data for user to fill in the email

so when user will open that url he.she will get the page to fill data.

Now because now url is from your own website you can write aspx code to perform whatever you want.
Naresh Kumar replied to dipa ahuja on 13-Jul-11 02:43 AM
Thanks for your reply.

I have already suggested the same, but I need to implement in this way only as per client.

Any suggestions or links!!!

Much Appreciate your help.