Click here to Skip to main content
14,389,928 members
Rate this:
Please Sign up or sign in to vote.
See more:
protected void Button1_Click(object sender, EventArgs e)
         SmtpClient smtp= new SmtpClient("", 587);
         smtp.EnableSsl = true;
         smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
         smtp.UseDefaultCredentials = false;
         smtp.Credentials = new System.Net.NetworkCredential("", "password");
         smtp.Timeout = 30000;

       MailMessage message = new MailMessage();
       message.From = new MailAddress("");
       message.Subject = "Test Mail";
       message.Body = "This is for testing SMTP mail from GMAIL";
         Response.Write("E-mail sent!");
        catch (Exception ex)
            Response.Write("Could not send the e-mail - error: " + ex.Message);
Updated 8-Jun-15 2:22am
F-ES Sitecore 8-Jun-15 5:03am
Please do basic research like using google before asking a question, this has to be one of the most frequently asked questions and there are a ton of articles that cover sending email through gmail and the issues you might have (often it's not your code but the fact that you haven't configured your account to allow emails to be automated). If you really want to solve this issue then google is your friend, however the proper solution to your problem is to not send emails through gmail at all
Rate this:
Please Sign up or sign in to vote.

Solution 1

Make sure the username and password is correct in the line:
smtp.Credentials = new System.Net.NetworkCredential("", "password");

try commenting the line :
smtp.UseDefaultCredentials = false;

Also try setting the properties outside the constructor:
smtp.Host = "";
smtp.Port = 587;
Rate this:
Please Sign up or sign in to vote.

Solution 2


Check the solution 1 after follow this below steps.

1)[^] //Click allow access to your Google account

2) You have to enable login from other timezone / ip for your google account.

to do this follow the link[^] and allow access by clicking the continue button.

3) go to security settings at the followig link[^] and enable less secure apps . So that you will be able to login from all apps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100