Check your google account in following website
You will need to check the security setting and make sure you allow the login if it alerts
https://myaccount.google.com/u/1/
Enable the less secure apps setting inside google
This is required
https://myaccount.google.com/lesssecureapps
Go to DisplayUnlockCaptcha
This seems required, after this setting it’s able to send email, otherwise Gmail blocked the connection
https://accounts.google.com/b/0/DisplayUnlockCaptcha
Sign in using an app password
https://support.google.com/accounts/answer/185833
Refer to following url on how to use curl to send email to gmail – this some how failed in ubuntu
https://medium.com/digital-thai-valley/call-gmail-smtp-with-curl-b15a96dc722d
Following is the code that used to send the email
using System;
using System.Net;
using System.Net.Mail;
namespace SendEmailTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Begining to send an email now");
var fromAddress = new MailAddress("fromemail@gmail.com", "From Name");
var toAddress = new MailAddress("toemaili@gmail.com", "To Name");
const string fromPassword = "PASSWORD";
const string subject = "TEST";
const string body = "TEST Email Body";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
smtp.Send(message);
}
Console.WriteLine("Finished Email send");
}
}
}