I want send Info on particular E-Mail ID when click on send button on form in ASP .Ne

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sachin satav
    New Member
    • Nov 2012
    • 1

    I want send Info on particular E-Mail ID when click on send button on form in ASP .Ne

    I want send Info on particular E-Mail ID when click on send button on form in ASP .Net [in C#] .
  • VanessaMeacham
    New Member
    • Sep 2012
    • 31

    #2
    HI ! i am not sure that it will help you perfectly but i tried for little-bit help you.

    Code:
    protected void SendMail()
    {
        // Gmail Address from where you send the mail
        var fromAddress = "Gmail@gmail.com";
        // any address where the email will be sending
        var toAddress = YourEmail.Text.ToString(); 
        //Password of your gmail address
        const string fromPassword = "Password";
         // Passing the values and make a email formate to display
        string subject = YourSubject.Text.ToString();
        string body = "From: " + YourName.Text + "\n";
        body += "Email: " + YourEmail.Text + "\n";
        body += "Subject: " + YourSubject.Text + "\n";
        body += "Question: \n" + Comments.Text + "\n";
        // smtp settings
        var smtp = new System.Net.Mail.SmtpClient();
        {
            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
            smtp.Timeout = 20000;
        }
        // Passing values to smtp object
        smtp.Send(fromAddress, toAddress, subject, body);
    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            //here on button click what will done 
            SendMail();
            DisplayMessage.Text = "Your Comments after sending the mail";
            DisplayMessage.Visible = true;
            YourSubject.Text = "";
            YourEmail.Text = "";
            YourName.Text = "";
            Comments.Text = "";
        }
        catch (Exception) { }
    }
    Last edited by Rabbit; Nov 29 '12, 04:11 PM. Reason: Please use code tags when posting code.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      There is an insight here on Bytes titled: Quick Reference on how to send an email using .NET that will get you pointed in the right direction.


      -Frinny

      Comment

      Working...