Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir i am trying to send email through asp.net application but i am not able to send email plz send me a code or send me a link for this
Posted

Try using the following code, hope it will work. Change credentials (UserName & Password) and receiver address according to yours.
C#
SmtpClient client = new SmtpClient();
      client.DeliveryMethod = SmtpDeliveryMethod.Network;
      client.EnableSsl = true;
      client.Host = "smtp.gmail.com";
      client.Port = 587;

      // setup Smtp authentication
      System.Net.NetworkCredential credentials =
          new System.Net.NetworkCredential("gmailusername@gmail.com", "gmailpassword");
      client.UseDefaultCredentials = false;
      client.Credentials = credentials;

      MailMessage msg = new MailMessage();
      msg.From = new MailAddress("gmailusername@gmail.com");
      msg.To.Add(new MailAddress("xyz@gmail.com"));
      msg.Subject = "This is a test Email subject";
      msg.IsBodyHtml = true;
      msg.Body = string.Format("<html><head></head><body>Test HTML Email</body>");
      try
      {
          client.Send(msg);
          //lblMsg.Text = "Your message has been successfully sent.";
      }

      catch (Exception ex)
      {
          //lblMsg.ForeColor = Color.Red;
          //lblMsg.Text = "Error occured while sending your message." + ex.Message;

      }

Make sure you have removed all mail settings from your web.config file.

Let me know if there is any issue.
 
Share this answer
 
Comments
ProEnggSoft 30-Mar-12 6:06am    
5!
Monjurul Habib 1-Apr-12 14:41pm    
thanks!
 
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