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.         protected void Page_Load(object sender, EventArgs e) {}  
  11.         protected void Button1_Click(object sender, EventArgs e) {  
  12.             try {  
  13.                 string Senderid = "[email protected]"// Your(Sender's) Email ID  
  14.                 string SenderPassword = "********"// Your Password  
  15.                 string Reciever_id = TextBox1.Text; // Reciever's Email ID  
  16.                 SmtpClient smtp = new SmtpClient() {  
  17.                     Host = "smtp.gmail.com",  
  18.                     Port = 587,  
  19.                     EnableSsl = true,  
  20.                     DeliveryMethod = SmtpDeliveryMethod.Network,  
  21.                     Credentials = new System.Net.NetworkCredential(Senderid, SenderPassword),  
  22.                     Timeout = 30000,  
  23.                 };  
  24.                 MailMessage message = new MailMessage(Senderid, Reciever_id, "SUBJECT""BODY ");  
  25.                 // (SUBJECT = Subject of the mail)  
  26.                 // (BODY = Message or body)  
  27.                 smtp.Send(message);  
  28.                 Response.Write("Mail Sent Successfully");  
  29.             } catch (Exception ex) {  
  30.                 ex.Message.ToString();  
  31.             }  
  32.         }  
  33.     }  
  34. }  
Note: Only the subject and the body changes as per application. You can integrate this code for Email Verification, Forgot Password, etc.