<t>Be sure to use System.Net.Mail, not the deprecated System.Web.Mail. Doing SSL with System.Web.Mail is a gross mess of hacky extensions.<br/>
<br/>
using System.Net;<br/>
using System.Net.Mail;<br/>
<br/>
var fromAddress = new MailAddress("from@gmail.com", "From Name");<br/>
var toAddress = new MailAddress("to@example.com", "To Name");<br/>
const string fromPassword = "fromPassword";<br/>
const string subject = "Subject";<br/>
const string body = "Body";<br/>
<br/>
var smtp = new SmtpClient<br/>
{<br/>
Host = "smtp.gmail.com",<br/>
Port = 587,<br/>
EnableSsl = true,<br/>
DeliveryMethod = SmtpDeliveryMethod.Network,<br/>
UseDefaultCredentials = false,<br/>
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)<br/>
};<br/>
using (var message = new MailMessage(fromAddress, toAddress)<br/>
{<br/>
Subject = subject,<br/>
Body = body<br/>
})<br/>
{<br/>
smtp.Send(message);<br/>
}<br/>
<br/>
```<br/>
<br/>
Additionally go to the [*Google Account > Security*](https://myaccount.google.com/security) page and look at the *Signing in to Google > 2-Step Verification* setting.<br/>
<br/>
- If it is enabled, then you have to generate a password allowing .NET to bypass the 2-Step Verification. To do this, click on [*Signing in to Google > App passwords*](https://myaccount.google.com/apppasswords), select app = Mail, and device = Windows Computer, and finally generate the password. Use the generated password in the `fromPassword` constant instead of your standard Gmail password.<br/>
<br/>
- If it is disabled, then you have to turn on [*Less secure app access*](https://myaccount.google.com/lesssecureapps), which is not recommended! So better enable the 2-Step verification.</t>