Hi
i have 1 aspx page which has mail button when ever i click on that send page should open where i will enter data then on clicking on send button mail should be send.
Please let what and where changes have to be done.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Mohammed Rehan Abdul Rehman4 reputationPosted Jan 10, 2013, 12:32 AM EST
using System.Net.Mail;
public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
{
try
{
MailMessage mMailMessage = new MailMessage();
mMailMessage.From = new MailAddress(from);
mMailMessage.To.Add(new MailAddress(to));
if ((bcc != null) && (bcc != string.Empty))
{
mMailMessage.Bcc.Add(new MailAddress(bcc));
}
if ((cc != null) && (cc != string.Empty))
{
mMailMessage.CC.Add(new MailAddress(cc));
}
mMailMessage.Subject = subject;
mMailMessage.Body = "" + body + "";
mMailMessage.IsBodyHtml = true;
mMailMessage.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Host = "your website url";
client.EnableSsl = false;
client.Port = 25;
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("your mail-id", "your password");
client.UseDefaultCredentials = true;
client.Credentials = credentials;
client.Send(mMailMessage);
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
}
}
protected void btnSend_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
sb.Append("
Enquiry");
sb.Append("
");
sb.Append("Name : " + "" + txtName.Text);
sb.Append("
");
sb.Append("Email : " + "" + txtEmail.Text);
sb.Append("
");
sb.Append("Phone Number : " + "" + txtPhone.Text);
sb.Append("
");
sb.Append("Message : " + "" + txtMessage.Text);
string EmailBody = sb.ToString();
SendMailMessage("your mail-id", "receiver mail-id", "", "", "Enquiry", EmailBody);
Response.Write("");
}