none
VBA gmail mail send fail RRS feed

  • Question

  • I googled and tried several VBA code to send email using gmail but failed.

    https://www.youtube.com/watch?v=cOhupIT0rNA

    Every code I tried failed when sending by runtime error .

    How could I do this ?

    Public Function send_email()

    Set cdomsg = CreateObject("CDO.message")
    With cdomsg.Configuration.Fields
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
    .Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 587
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "hoge@gmail.com"
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "hoge"
    .Update
    End With
    ' build email parts
    With cdomsg
    .To = "hoge@gmail.com"
    .From = "hoge@gmail.com"
    .Subject = "the email subject"
    .TextBody = "the full message body goes here. you may want to create a variable to hold the text"
    .send
    End With
        Set cdomsg = Nothing
    End Function


    Monday, July 7, 2014 6:03 PM

All replies

  • Could you please answer the following?

    1. What exactly is the error you are running into?
    2. What line does the code throw the error?
    3. Where have you declared your variables?

    Happy to help ! When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answered

    Tuesday, July 8, 2014 1:43 PM
  • Use "smptserverport" = 465

    Try to look deferences via my article: CDO - Mail wysyłany inaczej


    Oskar Shon, Office System MVP - www.VBATools.pl
    if Helpful; Answer when a problem solved

    Tuesday, July 8, 2014 2:19 PM
    Answerer
  • Thank you very much.

    I could send email using 465 port but  telnet smtp.gmail.com 465 return error . Why was it ?

    Tuesday, July 8, 2014 9:59 PM
  • Would you look on the code I was written?

    Paste you account data and try.


    Oskar Shon, Office System MVP - www.VBATools.pl
    if Helpful; Answer when a problem solved

    Wednesday, July 9, 2014 8:15 AM
    Answerer
  • Thank you.

    I could send email using 465 port.Thank you.

    But  telnet smtp.gmail.com 465 return error . Why was it ?

    Thursday, July 10, 2014 12:11 AM
  • This is a questions to your internet provider or check your AV/FW.

    I can, from any connections.


    Oskar Shon, Office System MVP - www.VBATools.pl
    if Helpful; Answer when a problem solved

    Thursday, July 10, 2014 11:48 AM
    Answerer