Good Morning, I have been trying to figure out how to send gmail using vba in Microsoft Access. I feel like the below code is correct as it's the same on every tutorial, instructions and research blog that I've found over the past week. I feel like I'm missing something else that I should be doing. I have enabled the IMAP on my google account. I have turned on 2 step authentication and received the APP password.
The error that I keep getting says: "The transport failed to connect to the server"
Any research direction or help on this issue is appreciated.
The error that I keep getting says: "The transport failed to connect to the server"
Any research direction or help on this issue is appreciated.
Code:
Private Sub sendgmail_Click()
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 = "Testing Gmail Sending ability"
.From = "enter_from_email"
.To = "enter_to_email"
.CC = ""
.BCC = ""
' To set email body as HTML, use .HTMLBody
' To send a complete webpage, use .CreateMHTMLBody
.TextBody = "This is a test email."
End With
msConfigURL = "[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration"[/URL]
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") = "enter_gmail"
.Item(msConfigURL & "/sendpassword") = "enter_gmail_App_Password"
.Update
End With
newMail.Configuration = mailConfiguration
newMail.Send
MsgBox "E-Mail 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