none
Can't send email through CDO with Vbscript but works with VBA RRS feed

  • Question

  • Hi all

    I'm trying to send email with CDO using Vbscript.

    In the line with the method send I receive the message "The transport failed to connect to the server"

    Then I make a copy paste from the code in vbscript to a module in Excel or access VBA And it runs fine !!

    in vba works fine with 0, 1 or 2 to the .Item(cdoSMTPAuthenticate)  property

    I change nothing !!

    I'vd already try lots of changes: SMTPAuthenticate, SMTPConnectionTimeout, SMTPServerPort etc.

    Can someone give an hint so I can improve my dialogue with the SMTP server guys

    They talk about an old server with Lotus Notes based in a Linux server....

    My code:

    Option Explicit
    
    Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
    Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
    Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/nntpauthenticate"
    Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
    Const cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
    Const cdoSendUsingPort = 2
    Const cdoDispositionNotificationTo = "urn:schemas:mailheader:disposition-notification-to"
    Const cdoReturnReceiptTo = "urn:schemas:mailheader:return-receipt-to"
    Const cdoReturnPath = "urn:schemas:mailheader:return-path"
    
    Const cdoDSNDefault = 0
    Dim NN, cdoConfig, cdoMessage
    
    Set cdoConfig = CreateObject("CDO.Configuration")
    
           With cdoConfig.Fields
                    .Item(cdoSendUsingMethod) = cdoSendUsingPort
                    .Item(cdoSMTPServer) = "mySMTP.server"
                    .Item(cdoSMTPAuthenticate) = 2 also tried 0, 1 in vba 
                    .Item(cdoSMTPServerPort) = 25
                    .Item(cdoSMTPConnectionTimeout) = 180
                    .Update
            End With
    
    
    Set cdoMessage = CreateObject("CDO.Message")
    
    With cdoMessage
        Set .Configuration = cdoConfig
        .Fields(cdoDispositionNotificationTo) = "myunit@myorganization.com"
        .Fields(cdoReturnReceiptTo) = "myunit@myorganization.com"
        .DSNOptions = cdoDSNDefault
        .MDNRequested = False
        .From = "myunit@myorganization.com"
        .To = "myemail@myorganization.com"
        .Subject = "Teste CDO Message " & CStr(NN)
        .TextBody = "Teste CDO Message."
        MsgBox "stop"
        .Send
    End With
    
    Set cdoMessage = Nothing
    Set cdoConfig = Nothing
    
    

    Thanks.

    João


    Joao Simplicio Rodrigues

    Monday, January 28, 2019 6:26 PM

Answers

  • This is usually because the CSCRIPT WSH program is not allowed through your firewall or the corporate firewall.

    As you have posted it is not a scripting error but a system configuration error which is what "The transport failed to connect to the server"

    As Olaf has noted PowerShell would be easier and can do all of this in one command. Also, if you are using an MSN linked account then Office products require no authentication nd will likely ignore the authentication type.


    \_(ツ)_/



    Monday, January 28, 2019 6:58 PM

All replies

  • You should make your life easier and use Powershell. There you can use Send-MailMessage to send mails.

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Monday, January 28, 2019 6:37 PM
  • This is usually because the CSCRIPT WSH program is not allowed through your firewall or the corporate firewall.

    As you have posted it is not a scripting error but a system configuration error which is what "The transport failed to connect to the server"

    As Olaf has noted PowerShell would be easier and can do all of this in one command. Also, if you are using an MSN linked account then Office products require no authentication nd will likely ignore the authentication type.


    \_(ツ)_/



    Monday, January 28, 2019 6:58 PM
  • PowerShell also tried but have to get time to learn more...

    jrv what you wrote make sense, when you mention the corporate firewall.

    Thank you both for reply.


    Joao Simplicio Rodrigues

    Monday, January 28, 2019 7:25 PM