Archived Forum PostQuestion:
Hi, I have a VB.NET application in i am trying to send GMAIL mails using the GMAIL OAUTH2 API`s provided on Chilkat. The link which i am following is:
http://www.example-code.com/vbnet/smtp_gmailOAuth2.asp
Now the issue is that, i have everything by the book which is described here but still i am getting this error at the tail end. I wont print the whole Error Log but i think this is the error:
"failed to login using XOAUTH2 method".
The code i am using is this:
Dim iss As String = "********"
Dim scope As String = "https://mail.google.com/"
Dim sub1 As String = ""
Dim numSec As Integer = 3600
Dim accessToken As String = http.G_SvcOauthAccessToken(iss, scope, sub1, numSec, cert)
If (accessToken = vbNullString) Then
Console.WriteLine(http.LastErrorText)
Exit Function
Else
Console.WriteLine("access token: " & accessToken)
End If
Dim mailman As New Chilkat.MailMan()
' Set the properties for the GMail SMTP server:
mailman.SmtpHost = "smtp.gmail.com"
mailman.SmtpPort = 587
mailman.StartTLS = True
mailman.SmtpUsername = "retroaa123@gmail.com"
mailman.OAuth2AccessToken = accessToken
' Create a new email object
Dim email As New Chilkat.Email()
email.Subject = "This is a test"
email.Body = "This is a test"
email.From = "retroaa123@gmail.com"
success = email.AddTo("Myself", "retroaa123@gmail.com")
' To add more recipients, call AddTo, AddCC, or AddBcc once per recipient.
' Call SendEmail to connect to the SMTP server and send.
' The connection (i.e. session) to the SMTP server remains
' open so that subsequent SendEmail calls may use the
' same connection.
success = mailman.SendEmail(email)
The LastErrorText is :
ChilkatLog:
SendEmail:
DllDate: Oct 29 2015
ChilkatVersion: 9.5.0.54
UnlockPrefix: 30-day trial
Username: RMOPS34:Haris.Tasawar
Architecture: Little Endian; 32-bit
Language: .NET 4.5
VerboseLogging: 0
sendEmailInner:
renderToMime:
createEmailForSending:
xSigningAlg: sha1
Auto-generating Message-ID
--createEmailForSending
renderToMime: Elapsed time: 0 millisec
--renderToMime
sendMimeInner:
progressTotal: 584
ensureSmtpSession:
ensureSmtpConnection:
SmtpHost: smtp.gmail.com
SmtpPort: 587
SmtpUsername: retroaa123@gmail.com
SmtpSsl: 0
StartTLS: 1
smtpConnect:
smtpHostname: smtp.gmail.com
smtpPort: 587
connectionIsReady:
Need new SMTP connection
--connectionIsReady
smtpSocketConnect:
socketOptions:
SO_SNDBUF: 262144
SO_RCVBUF: 4194304
TCP_NODELAY: 1
SO_KEEPALIVE: 1
--socketOptions
--smtpSocketConnect
smtpGreeting:
readSmtpResponse:
SmtpCmdResp: 220 smtp.gmail.com ESMTP w124sm28507454wmg.17 - gsmtp
--readSmtpResponse
--smtpGreeting
startTLS:
Will be using STARTTLS...
sendCmdToSmtp:
SmtpCmdSent: EHLO RMOPS34<crlf>
--sendCmdToSmtp
readSmtpResponse:
SmtpCmdResp: 250-smtp.gmail.com at your service, [80.227.130.130]
SmtpCmdResp: 250-SIZE 35882577
SmtpCmdResp: 250-8BITMIME
SmtpCmdResp: 250-STARTTLS
SmtpCmdResp: 250-ENHANCEDSTATUSCODES
SmtpCmdResp: 250-PIPELINING
SmtpCmdResp: 250-CHUNKING
SmtpCmdResp: 250 SMTPUTF8
--readSmtpResponse
sendCmdToSmtp:
SmtpCmdSent: STARTTLS<crlf>
--sendCmdToSmtp
readSmtpResponse:
SmtpCmdResp: 220 2.0.0 Ready to start TLS
--readSmtpResponse
TLS connection established.
--startTLS
ehloCommand:
sendCmdToSmtp:
SmtpCmdSent: EHLO RMOPS34<crlf>
--sendCmdToSmtp
readSmtpResponse:
SmtpCmdResp: 250-smtp.gmail.com at your service, [80.227.130.130]
SmtpCmdResp: 250-SIZE 35882577
SmtpCmdResp: 250-8BITMIME
SmtpCmdResp: 250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
SmtpCmdResp: 250-ENHANCEDSTATUSCODES
SmtpCmdResp: 250-PIPELINING
SmtpCmdResp: 250-CHUNKING
SmtpCmdResp: 250 SMTPUTF8
--readSmtpResponse
--ehloCommand
--smtpConnect
--ensureSmtpConnection
ensureSmtpAuthenticated:
smtpAuthenticate:
smtp_host: smtp.gmail.com
smtp_port: 587
smtp_user: retroaa123@gmail.com
smtpAuthenticate:
login_method: XOAUTH2
auth_xoauth2:
username: retroaa123@gmail.com
sendCmdToSmtp:
SmtpCmdSent: {PasswordOrCredentials}
--sendCmdToSmtp
readSmtpResponse:
SmtpCmdResp: 334 eyJzdGF0dXMiOiI0MDAiLCJzY2hlbWVzIjoiQmVhcmVyIiwic2NvcGUiOiJodHRwczovL21haWwuZ29vZ2xlLmNvbS8ifQ==
--readSmtpResponse
--auth_xoauth2
Failed to login using XOAUTH2 method
--smtpAuthenticate
ConnectionType: SSL/TLS
--smtpAuthenticate
--ensureSmtpAuthenticated
--ensureSmtpSession
--sendMimeInner
--sendEmailInner
Failed.
--SendEmail
--ChilkatLog
Any help would be appreciated.
Thanks, Haris.