Sending Emails using GMail in C#

Download source code

oAuth1.AuthUrl = "https://accounts.google.com/o/oauth2/auth";
oAuth1.TokenUrl = "https://accounts.google.com/o/oauth2/token";
oAuth1.RedirectUrl = "http://localhost";
oAuth1.ClientID = "421475025220-6khpgoldbdsi60fegvjdqk2bk4v19ss2.apps.googleusercontent.com";
oAuth1.ClientSecret = "_4HJyAVUmH_iVrPB8pOJXjR1";
oAuth1.Scope = "https://mail.google.com/";

smtp1.Server = "smtp.gmail.com";
smtp1.Port = 587;
smtp1.UseTls = ClientTlsMode.Explicit;

smtp1.UserName = "user...@gmail.com";

smtp1.Authorization = oAuth1.GetAuthorization();

smtp1.Open();

mailMessage1.BuildMessage("Hello, world!", "");
mailMessage1.From.FullAddress = "user...@gmail.com";
mailMessage1.ToList.EmailAddresses = "anderson@domain.com";
mailMessage1.Subject = "Subject line";

smtp1.Send(mailMessage1);

smtp1.Close();
 

Add Feedback