Quantcast
Channel: CodeProject Latest postings for ASP.NET
Viewing all articles
Browse latest Browse all 3938

.Net Core V2.2 - Sending email or gmail using OAuth2 or secure settings in Gmail in the background without browser auth

$
0
0
I thought this would be pretty simple to do, but has turned into a circular headache.

It's hard to find info on the internet on this subject, for most are using MailKit and MimeKit, others using SendGrid.
Plus I read that SmtpClient has been obsoleted as well with MailKit being reccomended.

So I have my secrets file working,
My Google OAuth2 Credentials have been tested and works.
Altered my Startup.cs to add Google credentials to services.
Altered my Startup.cs to services.AddAuthentication().AddGoogle
I did the example that opens up the browser to a Google Auth Page, writes the token with successful auth.

So here is my circular headache ....
Using Nuget MailKit/MimeKit, it doesn't register with .Net Core V2.2
Using Nuget SendGrid, same thing, doesn't register, get the caution or warning icon in dependencies nuget.

I can do this now, but I don't have any code to actually send the email.
var secrets = new Google.Apis.Auth.OAuth2.ClientSecrets
{
    ClientId = Environment.GetEnvironmentVariable("GMailClientId"),
    ClientSecret = Environment.GetEnvironmentVariable("GMailClientSecret")
};

var googleCredentials = await GoogleWebAuthorizationBroker.AuthorizeAsync(secrets, new[] { GmailService.Scope.MailGoogleCom }, email, CancellationToken.None);
if (googleCredentials.Token.IsExpired(SystemClock.Default))
{
    await googleCredentials.RefreshTokenAsync(CancellationToken.None);
}

I'm not sure which way I should proceed.
I can't find any references, or documentation for .Net Core V2.2

I must admit that the SendGrid SAS looks pretty cool for sending email from my website.
Any help would be appreciated!
If it ain't broke don't fix it
Discover my world at jkirkerx.com

Viewing all articles
Browse latest Browse all 3938

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>