Padawan018
Board Regular
- Joined
- Sep 29, 2006
- Messages
- 63
I have a code that is supposed to send an email using Gmail but it fails at the .Send line in the code with the error:
"The Transport failed to connect to the server."
I have looked up other post online and tried changing from server port 25 and 465 but with the same results.
Here is the code I am using, which is loaded from a form to get the email, password, and message.
See my module code below.
"The Transport failed to connect to the server."
I have looked up other post online and tried changing from server port 25 and 465 but with the same results.
Here is the code I am using, which is loaded from a form to get the email, password, and message.
See my module code below.
Code:
Sub SendEmailUsingGmail(email As String, pw As String, msg As String)
Dim NewMail As CDO.Message
Dim msgConf As CDO.Configuration
' Object creation
Set NewMail = CreateObject("CDO.Message")
Set msgConf = CreateObject("CDO.Configuration")
' Server Configuration
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = email
msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = pw
msgConf.Fields.Update
'Set All Email Properties
With NewMail
.Subject = "Excel Tool"
.From = email
.To = "testEmail@gmail.com"
.CC = ""
.BCC = ""
.TextBody = msg
.Configuration = msgConf
.Send
End With
MsgBox ("The Message has been sent")
'Set the NewMail Variable to Nothing
Set NewMail = Nothing
Set msgConf = Nothing
End Sub