I would like to learn how to send emails using Mailkit. The problem is that I now use 2-factor authentication in my gmail account, so I can not use simplified mail sending options. According to Mailkit documentation - Oath needs to be used.
So I registered a new application in Google API and got the secret key. Then I try to authenticate like this:
var secrets = new ClientSecrets
{
ClientId = "xxxx",
ClientSecret = "yyyy"
};
var scopes = new string[] { GmailService.Scope.MailGoogleCom };
var googleCredentials = await GoogleWebAuthorizationBroker.AuthorizeAsync(secrets, scopes, email, CancellationToken.None);
if (googleCredentials.Token.IsExpired(SystemClock.Default))
{
await googleCredentials.RefreshTokenAsync(CancellationToken.None);
}
Upon reaching the AuthorizeAsync
line - a new browser window is opened where I have to enter my credentials.. This wouldn't be a problem if I were to run this application on Windows.. BUT, this is a huge problem.
I am building a console dotnet core application, which is meant to run in a Linux environment, in a CLI mode. I can't afford to ask to enter credentials each time token is expired.. because there is no GUI at all...
Is there a way I can make email sending "just" work without additional logins in external apps?
It has just occurred to me, that maybe it will be easier to register a new email account with simplified login option and use it in my apps instead of trying to make current Gmail account work.. So, any ideas or suggestions?