No longer able to send e-mails with VBA and google smtp - Additional Info

Viewed 168

Similar problem to "Resca's" Utility to send email to Gmail stopped working after google implemented OAuth. I have an excel workbook using VBA to ONLY SEND individual gmails to multiple “google group” members. It had been working for 4 years until Gmail added Oauth.

I have done tests with OAuth code from "Email Architect". I can test the app in test mode and it will send the email if I click passed the alarms and add include read. Compose, send and delete permissions. When I configure it as production I get not verified message and go through a similar routine that "test" needed. When I try to verify the Gmail API it requires a domain which I don't have. This is run under a single user xxx@gmail with owner permission from my disk. After seeing Resca's post, I think I may be over doing the OAuth.

I am not a programmer, but have vintage experience with assembler, macro and micro code, but not high level languages. Self taught VBA/Excel I got parts of this code from "Jean-François Corbett" @ https://stackoverflow.com Tonyyy at MRexcel.com

Set CDO_Mail = CreateObject("CDO.Message")
On Error GoTo Error_Handling

Set CDO_Config = CreateObject("CDO.Configuration")
CDO_Config.Load -1

Set SMTP_Config = CDO_Config.Fields

With SMTP_Config
 .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
 .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "xxxxx@gmail.com"
 .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxx"
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
                    '25 & 465 are valid ports and sometimes may fail. Change to the other if you can't connect
 .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
 .Update
End With

With CDO_Mail
 Set .Configuration = CDO_Config

End With

CDO_Mail.Subject = strSubject
CDO_Mail.From = strFrom
CDO_Mail.To = strTo
CDO_Mail.TextBody = strBody
CDO_Mail.CC = strCc
CDO_Mail.BCC = strBcc
CDO_Mail.Send
1 Answers

To be clear Google did not add Oauth2. The option of using Xoauth2 with the smtp server has always been there. Nor is google forcing you to use Xoauth2 with the smtp server.

What google did was remove the option for Less secure apps & your Google Account. Which allowed you to use the google account password to connect to the smtp server.

If you have 2fa enabled on the google account you can create an apps password and use that password instead of the actual password for the google account in your code.

.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "AppsPassword"

If you do not want to use an apps password then yes you will need to configure Xoauth2. xoauth2-protocol Its been a very long time since i have touched VBA I dont think this is something i can help with. But a quick google search shows it should be supported Oauth

Related