Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i send an email into my gmail from an .aspx page in asp.net using c#
Posted

 
Share this answer
 
Try using the following code, hope it will work. Change credentials (UserName & Password) and receiver address according to yours.

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;

      }
 
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