Tuesday, 31 July 2012

How to send mails in asp.net









using System.Net;
using System.Net.Mail;
--------------------------------------
Copy below code in pageload:

try
    {
MailMessage mm = newMailMessage(TextBox1.Text, TextBox2.Text, TextBox3.Text,                                          TextBox4.Text);
      mm.IsBodyHtml = false;
NetworkCredential nc = newNetworkCredential("Your gamil id", "your gmail password");
SmtpClient sc = newSmtpClient("SMTP.gmail.com", 587);
      sc.EnableSsl = true;
       sc.UseDefaultCredentials = false;
       sc.Credentials = nc;
       sc.Send(mm);
      Label1.Text = "mail sended sucessfully";
   }
catch (Exception ex)
        {
            Response.Write(ex.Message);
        }


----------------------------------
Hints:
textbox1.text=fromaddress
textbox2.text=toaddress
textbox3.text=subject
textbox4.text=matter
              now u can understand why we placed textboxes and labels in design page.....
 to send mails provide your valied gmail id and gmail password
Enjoy the code....!