none
Sending Email with gmail - the transport failed to connect to the server RRS feed

  • Question

  • Hi there,

    What am I doing wrong here pleaese ?

    Telnet on 587 and 25 does not work both from my workplace or from home. 

    I tried with Wireshark and excel is even not making an attempt to reach smtp.gmail.com

    What do you think is wrong ?

    Kind regards, 

    Peter

    Private Sub CommandButton1_Click()
    SendEmailUsingGmail
    End Sub

    Sub SendEmailUsingGmail()
       
    Dim NewMail As CDO.Message
       
    Set NewMail = New CDO.Message
      
    'Enable SSL Authentication
    NewMail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
      
    'Make SMTP authentication Enabled=true (1)
      
    NewMail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
      
    'Set the SMTP server and port Details
    'To get these details you can get on Settings Page of your Gmail Account
      
    NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
      
    NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587


      
    NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
      
    'Set your credentials of your Gmail Account
      
    NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myEmail@gmail.com"
      
    NewMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "myPassword123."
      
    'Update the configuration fields
    NewMail.Configuration.Fields.Update

       
    'Set All Email Properties
      
    '                            With NewMail
    '                              .Subject = "Test Mail from LearnExcelMacro.com"
    '                              .From = "myEmail@gmail.com"
    '                              .To = "myEmail@gmail.com;info@learnexcelmacro.com"
    '                              .CC = "myEmail@gmail.com"
    '                              .BCC = ""
    '                              .textbody = ""
    '                            End With

    'Send email with HTML body
    ' Never use same email in From and CC lest you get the Automation error !!!!

    With NewMail
      .Subject = "Test Mail from EXCEL"
      .From = "myEmail@gmail.com"
      .To = "piotr.myEmail@myEmail.com"
      .CC = "pmyEmail@vmexpertise.com"
      .BCC = ""
      .HTMLBody = "<HTML><BODY>OK. This is a HTML email from Excel.</BODY></html>"
    End With

    NewMail.Configuration.Fields.Update
      
    a = NewMail.Configuration
    property0 = NewMail.Configuration.Fields.Item(0).Name & " " & NewMail.Configuration.Fields.Item(0).Value
    property1 = NewMail.Configuration.Fields.Item(1).Name & " " & NewMail.Configuration.Fields.Item(1).Value
    property2 = NewMail.Configuration.Fields.Item(2).Name & " " & NewMail.Configuration.Fields.Item(2).Value
    property3 = NewMail.Configuration.Fields.Item(3).Name & " " & NewMail.Configuration.Fields.Item(3).Value
    property4 = NewMail.Configuration.Fields.Item(4).Name & " " & NewMail.Configuration.Fields.Item(4).Value
    property5 = NewMail.Configuration.Fields.Item(5).Name & " " & NewMail.Configuration.Fields.Item(5).Value
    property6 = NewMail.Configuration.Fields.Item(6).Name & " " & NewMail.Configuration.Fields.Item(6).Value
    property7 = NewMail.Configuration.Fields.Item(7).Name & " " & NewMail.Configuration.Fields.Item(7).Value
    property8 = NewMail.Configuration.Fields.Item(8).Name & " " & NewMail.Configuration.Fields.Item(8).Value
    property9 = NewMail.Configuration.Fields.Item(9).Name & " " & NewMail.Configuration.Fields.Item(9).Value
    property10 = NewMail.Configuration.Fields.Item(10).Name & " " & NewMail.Configuration.Fields.Item(10).Value
    property11 = NewMail.Configuration.Fields.Item(11).Name & " " & NewMail.Configuration.Fields.Item(11).Value

    NewMail.Send
    MsgBox ("Mail has been Sent")
      
    'Set the NewMail Variable to Nothing
    Set NewMail = Nothing
       
    End Sub



    God bless you all :)

    Sunday, May 8, 2016 6:38 PM

All replies