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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mohammed Rehan Abdul RehmanPosted Jan 10, 2013, 5:32 AM
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("");
}