title: C# sending email via Gmail account
body: <p>I am extending my Web App with simple CMD "Service", which should send verification email on newly registered user. My problem is by authenticating the Gmail account, where following exception is thrown:</p>
  
  <p><strong>"The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required."</strong></p>
  
  <p>I have tried authenticate on my own IMAP server, but it did not worked out too.
  Later I tried to use XAMP Mercury email server, which is not the best solution, due to depending entirely on local configuration, so I abandoned 
  that idea.
  In future, i want to create a new google account for the app only, so no maintenance is required.</p>
  
  <pre><code>  String body = "&lt;head&gt;" +
              "Here comes some logo" +
            "&lt;/head&gt;" +
            "&lt;body&gt;" +
              "&lt;h1&gt;Account confirmation reqest.&lt;/h1&gt;" + Environment.NewLine +
              "&lt;a&gt;Dear User, &lt;/a&gt;" + Environment.NewLine +
              "&lt;a&gt;In order to be able to use musicshop app properly, we require You to confirm Your email address.&lt;/a&gt;" + Environment.NewLine +
              "&lt;a&gt;This is the last step towards using our app.&lt;/a&gt;" + Environment.NewLine +
              "&lt;a&gt;Pleas follow this hyperlink to confirm your address.&lt;/a&gt;" + Environment.NewLine +
              "&lt;a&gt;[Callback url]&lt;/a&gt;" +
            "&lt;/body&gt;";
    try
    {
       SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
       smtpClient.UseDefaultCredentials = false;
       smtpClient.Credentials = new NetworkCredential()
       {
          UserName = "myemail@gmail.com",
          Password = "mypassword"
       };
       smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
       smtpClient.EnableSsl = true;
       smtpClient.Send("targetemail@targetdomain.xyz", "myemail@gmail.com", "Account verification", body);
    }
    catch (Exception ex)
    {
    }
  </code></pre>
  
  <p>I just want to be able to send an email via Gmail server, without any exceptions.
  Do I need any NuGet packages for that, use different approach?</p>