Send mail through ASP.NET

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Net.Mail;  
  8. namespace WebApplication1 {  
  9.     public partial class Frm_ForgotPassword: System.Web.UI.Page   
  10.     {  
  11.         protected void Page_Load(object sender, EventArgs e) {}  
  12.         protected void Button1_Click(object sender, EventArgs e)   
  13.         {  
  14.             try {  
  15.                 string Senderid = "[email protected]"// Your(Sender's) Email ID  
  16.                 string SenderPassword = "********"//   Your Password  
  17.                 string Reciever_id = TextBox1.Text; // Reciever's Email ID  
  18.   
  19.                 SmtpClient smtp = new SmtpClient() {  
  20.                     Host = "smtp.gmail.com",  
  21.                     Port = 587,  
  22.                     EnableSsl = true,  
  23.                     DeliveryMethod = SmtpDeliveryMethod.Network,  
  24.                     Credentials = new System.Net.NetworkCredential(Senderid, SenderPassword),  
  25.                     Timeout = 30000,  
  26.                 };  
  27.   
  28.                 MailMessage message = new MailMessage(Senderid, Reciever_id, "SUBJECT""BODY ");  
  29.                 // (SUBJECT = Subject of the mail)  
  30.                 // (BODY = Message or body)  
  31.   
  32.                 smtp.Send(message);  
  33.                 Response.Write("Mail Sent Successfully");  
  34.             }   
  35.             catch (Exception ex)   
  36.             {  
  37.                 ex.Message.ToString();  
  38.             }  
  39.         }  
  40.     }  
  41. }  
Note: Only the subject and the body changes as per application. You can integrate this code for Email Verification, Forgot                   Password,etc