SMTP Mail with CDO Error (1 Viewer)

tt1611

Registered User.
Local time
Today, 01:38
Joined
Jul 17, 2009
Messages
132
Guys can you please take a look at the below code and let me know your thoughts. The first bit errors out to runtime error 2147220973 "The transport failed to connect to the server"

Code:
'This code is courtesy of Ron de Bruin [URL="http://www.rondebruin.nl/cdo/htm"]www.rondebruin.nl/cdo/htm[/URL]
'The code will send an automated email to the ticket owner advicing closure (code has been modified for Intercall)
Dim iMsg As Object
    Dim iConf As Object
    Dim strbody As String
    Dim Flds As Variant
    Set iMsg = CreateObject("CDO.Message")
 
    Set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields
    With Flds
 
 
    iConf.Load -1    ' CDO Source Defaults
      'Sets up relevant fields
            .Item("[URL]http://schemas.microsoft.com/cdo/configuration/sendusing[/URL]") = cdoSendUsingPort
            .Item("[URL]http://schemas.microsoft.com/cdo/configuration/smtpserver[/URL]") = "someipaddress"
            .Item("[URL]http://schemas.microsoft.com/cdo/configuration/smtpserverport[/URL]") = 25
 
     iConf.Fields.Update
     End With
    strbody = "Hi Franklyn" & "," & vbNewLine & vbNewLine & _
              "Your Intercall ticket is now closed. Please refer to the ticket details if you have any questions." & vbNewLine & _
              " " & vbNewLine & _
              "We also appreciate any feedback you may have. Please log into Intercall and click the submit feedback button to send this through." & vbNewLine & _
              " " & vbNewLine & _
              "Thank you and regards" & vbNewLine & _
              " " & vbNewLine & _
              "DSN TEL: 475-8443" & vbNewLine & _
              "FAX: 475-7050" & vbNewLine & _
              "EMAIL: [EMAIL="MISHELPDESK@eur.army.mil"]someemail[/EMAIL]address" & vbNewLine & _
              "MIS Website: [EMAIL="MISHELPDESK@eur.army.mil"][COLOR=#0066cc]someemail[/COLOR][/EMAIL]address[URL="https://portal.eur.army.mil/sites/IMCOM-E-G/fmwr/nafsm/mis/default.aspx"]sites/IMCOM-E-G/fmwr/nafsm/mis/default.aspx[/URL]" & vbNewLine & _
              ""
    With iMsg
        Set .Configuration = iConf
        .To = "<[EMAIL="MISHELPDESK@eur.army.mil"][COLOR=#0066cc]someemail[/COLOR][/EMAIL]address>"
        .CC = ""
        .BCC = ""
        .From = "<[EMAIL="MISHELPDESK@eur.army.mil"][COLOR=#0066cc]someemail[/COLOR][/EMAIL]address>"
        .Subject = "Intercall ticket number" & " " & Form_FaultReview.txtid
        .TextBody = strbody
        .Send
    End With

The second bit does not throw any error. ( I have opened a watch of every variable and they are all filling out fine) but the message will not deliver to the specified email address

Code:
Dim iMsg As Object
    Dim iConf As Object
    Dim strbody As String
    Dim Flds As Variant
    Set iMsg = CreateObject("CDO.Message")
 
    Set iConf = CreateObject("CDO.Configuration")
    Set Flds = iConf.Fields
    With Flds
 
    Dim nResetIndex
    For nResetIndex = 0 To iConf.Fields.Count
    On Error Resume Next
           iConf.Fields.Delete nResetIndex
    Next
 
    iConf.Load -1    ' CDO Source Defaults
      'Sets up relevant fields
            .Item("[URL]http://schemas.microsoft.com/cdo/configuration/sendusing[/URL]") = cdoSendUsingPort
            .Item("[URL]http://schemas.microsoft.com/cdo/configuration/smtpserver[/URL]") = "someipaddress"
            .Item("[URL]http://schemas.microsoft.com/cdo/configuration/smtpserverport[/URL]") = 25
 
     iConf.Fields.Update
     End With
    strbody = "Hi Franklyn" & "," & vbNewLine & vbNewLine & _
              "Your Intercall ticket is now closed. Please refer to the ticket details if you have any questions." & vbNewLine & _
              " " & vbNewLine & _
              "We also appreciate any feedback you may have. Please log into Intercall and click the submit feedback button to send this through." & vbNewLine & _
              " " & vbNewLine & _
              "Thank you and regards" & vbNewLine & _
              " " & vbNewLine & _
              "DSN TEL: 475-8443" & vbNewLine & _
              "FAX: 475-7050" & vbNewLine & _
              "EMAIL: [EMAIL="MISHELPDESK@eur.army.mil"][COLOR=#0066cc]someemail[/COLOR][/EMAIL]address" & vbNewLine & _
              "MIS Website: [EMAIL="MISHELPDESK@eur.army.mil"][COLOR=#0066cc]someemail[/COLOR][/EMAIL]address[URL="https://portal.eur.army.mil/sites/IMCOM-E-G/fmwr/nafsm/mis/default.aspx"]/sites/IMCOM-E-G/fmwr/nafsm/mis/default.aspx[/URL]" & vbNewLine & _
              ""
    With iMsg
        Set .Configuration = iConf
        .To = "<[EMAIL="MISHELPDESK@eur.army.mil"][COLOR=#0066cc]someemail[/COLOR][/EMAIL]address>"
        .CC = ""
        .BCC = ""
        .From = "<[EMAIL="MISHELPDESK@eur.army.mil"][COLOR=#0066cc]someemail[/COLOR][/EMAIL]address>"
        .Subject = "Intercall ticket number" & " " & Form_FaultReview.txtid
        .TextBody = strbody
        .Send
    End With

I had to include the On Error Resume next line because while the delete in the loop was running it eventually errored out after the 6th go saying "the item could not be found in the specified list".

I think this had to do with it actioning a delete command on the iconf property and it could not find one of the items to delete a value from. Fast foward that, I get to the imsg variable and all properties are completing fine but not sending through the message.

Do you have any ideas on what I might be doing wrong?
 

John.Woody

Registered User.
Local time
Today, 06:38
Joined
Sep 10, 2001
Messages
354
I think its your source defaults. The 2nd one "someipaddress" unless you've removed the correct info, but other info is needed as well. Below is the config I use.
Code:
'==This section provides the configuration information for the remote SMTP server.

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtp

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = un

'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = pw

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

HTH
 

tt1611

Registered User.
Local time
Today, 01:38
Joined
Jul 17, 2009
Messages
132
Hey John
Thanks for getting back. I intentionally removed my server IP settings and other values (eg someemailaddress). You never know who to trust these day.

On your second note. I have been reviewing my code and adding and removing some other fields like you suggested.

Although I have confirmed our SMTP server does not require authentication, I stilltried adding a username and password field but still running into the transport could not connect...error. This is driving me mad

The code works perfectly off my test box for which i have admin rights and which is not on the domain but on a workgroup however when i try it on my regular network PC (which is what everyone else will be using to run the app) it errors out. I just done get it.
 

John.Woody

Registered User.
Local time
Today, 06:38
Joined
Sep 10, 2001
Messages
354
I have had this error on my remote server. It came and went by its self. I put it down to the connection from the remote server to the smtp server not being available. May be on the domain the smtp server is not available due to security settings, IP or port?... may be?
 

tt1611

Registered User.
Local time
Today, 01:38
Joined
Jul 17, 2009
Messages
132
I'll have to troubleshoot to see if the code is actually sending the message to the server with SA.
Just wanted to see if there were any issues with the code I may have overlooked and right now its looking like the issue may be beyond VBA. Thanks for checking on this for me John. If you have any other ideas to give on this, please let me know.

Thanks
 

Users who are viewing this thread

Top Bottom