Click here to Skip to main content
15,885,868 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all , i hope u r right ... i have my own site ...i created it by html.
and here is my Q: i created a text box and a button for users to put thier comments ..
now i what i want to do is that : when a user put his comment and press on the button ,,the comment should be sent to my emial .... how can i do it ????
Posted
Comments
wizardzz 10-Apr-12 18:17pm    
Have you looked anything up on google first?
R. Giskard Reventlov 10-Apr-12 18:23pm    
1: Don't use txtspk: you may be a 10 year old boy but we're not.
2: What have you tried for yourself? What research have you done?
prince najri 11-Apr-12 15:16pm    
thx bro ...i solved that problem ..thx again

1 solution

Use this code:

C#
 protected void Button1_Click(object sender, EventArgs e)
{
    System.Net.Mail.MailMessage MailMessage1 = new System.Net.Mail.MailMessage();
    //Add your mail address here:
    MailMessage1.To.Add("YourMailAdress");
    //Add your mail address here:
    MailMessage1.From = new System.Net.Mail.MailAddress("YourMailAdress");
    //Add your mail subject here:
    MailMessage1.Subject = "Mail Subject";
    //Change you textbox name here(if your textbox for comment has another name)
    MailMessage1.Body = TextBox1.Text;
    //Change this part if your smtp server use BodyHtml.
    MailMessage1.IsBodyHtml = false;

    System.Net.Mail.SmtpClient SmtpClient1 = new System.Net.Mail.SmtpClient();

    //Specify your smtp server:
    //Change to your smtp server name:
    SmtpClient1.Host = "smtp.gmail.com";
    //Change to your smtp server port:
    SmtpClient1.Port = 587;
    //Add your Email and password:
    SmtpClient1.Credentials = new System.Net.NetworkCredential("YourEmail", "Your Password");
    //Change this part if your smtp server do not use SSL.
    SmtpClient1.EnableSsl = true;

    try
    {
        SmtpClient1.Send(MailMessage1);
        //Mail sends successfully
        Response.Redirect("SendMailSuccess.aspx");
    }
    catch
    {
        //Failed to send mail
        Response.Redirect("SendMailFail.aspx");
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900