Question:
I have looked at the documentation about GMail and I quote:
GMail: If sending via smtp.gmail.com, then send with OAuth2 authentication if possible. Otherwise you will need to change your GMail account settings to allow for sending by less secure apps. See the links below.
I have reviewed the sample code that uses your HTTP library for the task in hand. However, I am already having to fund the Email library and at the moment it is beyond my circumstances to purchase an additional library.
Now, I have already written my own VB.NET utility to communicate with a GMail Calendar and I do the authentication like this:
Private Function DoAuthentication(ByRef rStrToken As String, ByRef rParameters As OAuth2Parameters) As Boolean
Dim credential As UserCredential
Dim Secrets = New ClientSecrets() With {
.ClientId = m_strClientID,
.ClientSecret = m_strClientSecret
}
'm_Scopes.Add(CalendarService.Scope.Calendar)
m_Scopes.Add("https://www.googleapis.com/auth/calendar https://www.google.com/m8/feeds/")
Try
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, m_Scopes,
"user", CancellationToken.None,
New FileDataStore("PublicTalkSoftware.Calendar.Application")).Result()
' Create the calendar service using an initializer instance
Dim initializer As New BaseClientService.Initializer() With {
.HttpClientInitializer = credential,
.ApplicationName = "GoogleCalIF"
}
m_Service = New CalendarService(initializer)
rStrToken = credential.Token.AccessToken.ToString()
rParameters.AccessToken = credential.Token.AccessToken
rParameters.RefreshToken = credential.Token.RefreshToken
Catch ex As Exception
' We encountered some kind of problem, perhaps they have not yet authenticated?
' Can we isolate that as the exception?
Return False
End Try
Return True
End Function
So what I am asking is if they is a similar way that I can do the authentication bit myself so that I can just pass the token needed into the mailman
object?
Thanks.
From what I can tell, I can use my same utility that I developed. I jus have to make sure it has requested to use the email API. Then, I follow the same code as above, but using the right scope.
Finally, I should be able to return the token string and just pass that as a parameter to your OAuth2 method.
Tha sound right?
I think I have sorted this one out. Things I needed to do:
I use that token with your Email method and it all works. :)