ExcelAtEverything
Active Member
- Joined
- Jan 30, 2021
- Messages
- 351
- Office Version
- 2019
- Platform
- Windows
Hello all,
I pulled the code below from YouTube, and I have it working perfectly with my personal Gmail account so that Excel sends an email with attachment thru Gmail. However when I try to use this exact same code, but I replace my personal Gmail acct with a company-issued Gmail account (it's a Google Workspace business account using the company domain) it returns a SMTP (0x80040217) error when attempting to send from that address. I checked to make sure that the SMTP settings were the same in Gmail settings, and there doesn't appear to be anything different between my personal Gmail acct and the business Gmail account, so I'm not sure how I can repair.
This is the only portion of the code I am changing (in addition to the "From:" email address to the same thing)
[/CODE]
And here's the full piece. Thanks so much for any help.
I pulled the code below from YouTube, and I have it working perfectly with my personal Gmail account so that Excel sends an email with attachment thru Gmail. However when I try to use this exact same code, but I replace my personal Gmail acct with a company-issued Gmail account (it's a Google Workspace business account using the company domain) it returns a SMTP (0x80040217) error when attempting to send from that address. I checked to make sure that the SMTP settings were the same in Gmail settings, and there doesn't appear to be anything different between my personal Gmail acct and the business Gmail account, so I'm not sure how I can repair.
This is the only portion of the code I am changing (in addition to the "From:" email address to the same thing)
VBA Code:
[CODE=vba] .Item(msConfigURL & "/sendusername") = "r*******g@gmail.com"
.Item(msConfigURL & "/sendpassword") = "T*****4"
And here's the full piece. Thanks so much for any help.
VBA Code:
Sub Send_Email_With_Gmail()
Dim newMail As CDO.Message
Dim mailConfiguration As CDO.Configuration
Dim fields As Variant
Dim msConfigURL As String
On Error GoTo errHandle
Set newMail = New CDO.Message
Set mailConfiguration = New CDO.Configuration
mailConfiguration.Load -1
Set fields = mailConfiguration.fields
With newMail
.Subject = "R*** ***** *** **-**-***1"
.From = "r*******g@gmail.com"
.To = "e****3@gmail.com"
.CC = ""
.BCC = ""
' To set email body as HTML, use .HTMLBody
' To send a complete webpage, use .CreateMHTMLBody
.TextBody = "Please see attached report."
.AddAttachment "C:\Users\********\Downloads\****** 7-13-2021 (PDF).pdf"
End With
msConfigURL = "http://schemas.microsoft.com/cdo/configuration"
With fields
.Item(msConfigURL & "/smtpusessl") = True
.Item(msConfigURL & "/smtpauthenticate") = 1
.Item(msConfigURL & "/smtpserver") = "smtp.gmail.com"
.Item(msConfigURL & "/smtpserverport") = 465
.Item(msConfigURL & "/sendusing") = 2
.Item(msConfigURL & "/sendusername") = "r*******g@gmail.com"
.Item(msConfigURL & "/sendpassword") = "T*****4"
.Update
End With
newMail.Configuration = mailConfiguration
newMail.Send
MsgBox "Email has been sent", vbInformation
exit_line:
'// Release object memory
Set newMail = Nothing
Set mailConfiguration = Nothing
Exit Sub
errHandle:
MsgBox "Error: " & Err.Description, vbInformation
GoTo exit_line
End Sub