CDO Email coming up with "The "SendUsing" configuration value is invalid" error on Windows 7

Posted on 2010-01-02
Last Modified: 2012-05-08
My old laptop needed replacing and the new one I bought runs on Windows 7 instead of XP. I have an Access Program that uses CDO Email. It works well on XP machines but is coming up with "The "SendUsing" configuration value is invalid." error on my Windows 7 machine. I am not stipulating my SMTP server so it should be using the default settings, which I found out on XP machines, seemed to be the settings loaded in Outlook Express (not Outlook). Outlook Express wont run on Windows 7 Home Premium so I have tried installing and configuring Windows Live Mail but that doesn't seem to have fixed the problem either. This application is being distributed to users with XP and OE so it works fine on their machines but the way it is, I can't test it on mine. Can anyone tell me what I need to do to configure it to work on Windows 7?

Following is the function I am using:

Function CDOEmail(sTo As String, _
                 CC As String, _
                 BCC As String, _
                 Subject As String, _
                 TextBody As String, _
                 Attachment As String, _
                 Optional SMTPserver As String, _
                 Optional DisplayPleaseWait As Boolean) As Boolean
          Dim iMsg As Object
          Dim iConf As Object
          Dim sSender As String
10        On Error GoTo CDOEmail_Error

20        If DisplayPleaseWait Then PleaseWait "Sending e-mail"

30        fLog "CDOMail", "CDOEmail sequence commencing: " & sTo & ", " & CC & ", " & BCC & ", " & Subject _
          & ", " & TextBody & ", " & Attachment

40        If Nz(gsStoreIdent, "") = "" Then
50            fLog "CDOEmail", "Initialiser launched because gsStoreIdent was: " & gsStoreIdent
60            Initialiser
70        End If
80        sSender = Nz(DLookup("Email", "tblStores", "Ident = '" & gsStoreIdent & "'"), EMAILTO)
90        sSender = Mid(sSender, 1, InStr(sSender, "@") - 1) & " <" & sSender & ">"
100       Set iMsg = CreateObject("CDO.Message")
110       Set iConf = CreateObject("CDO.Configuration")

120       If Len(SMTPserver) > 0 Then
              Dim Flds As Variant
130           iConf.Load -1    ' CDO Source Defaults
140           Set Flds = iConf.Fields
150           With Flds
160               .Item("") = 2
170               .Item("") _
                                 = SMTPserver
180               .Item("") = 25
190               .Update
200           End With
210       End If

220       On Error Resume Next
230       With iMsg
240           Set .configuration = iConf
250           .To = sTo
260           .CC = CC
270           .BCC = BCC
280           .FROM = sSender
290           .Subject = Subject
300           .TextBody = TextBody
310           If Dir(Attachment) <> "" And Attachment <> "" Then
320               .AddAttachment Attachment
330           End If
340           .Send
350           If Err.Number = -2147220973 Then
360               fLog "CDOEmail", "### Error ### The transport failed to connect to the server."
370               CDOEmail = 0
380           ElseIf Err Then
390               Stop
400               fLog "CDOEmail", "### ERROR ### Email failed to send " & Err.Number & " " & Err.Description
410               MsgBox "Error : " & Err.Number & " " & Err.Description & " Please note the details of this message."
420               CDOEmail = 0
430           Else
440               CDOEmail = -1
450           End If
460       End With

470       On Error GoTo 0
480       fLog "CDOMail", "CDOEmail sequence finished normally"
490       If DisplayPleaseWait Then PleaseWait , True
500       Exit Function


510       MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure CDOEmail of Module CDOMail"
520       If DisplayPleaseWait Then PleaseWait , True
Exit Function
End Function
Question by:Rob4077
    LVL 38

    Expert Comment

    Hi Rob,
    I don't know if this helps, but according to the following link, your code line 170 should be as shown below, and not as you have it.  You need to replace "myserver" with your server name.;leftCol
    objMessage.Configuration.Fields.Item _
    ("") = ""

    If there is a problem with your line 170 (I don't know for sure), it may not have shown up in your XP machine because the remote SMTP server already existed on that machine and that line in your code was not critical. Your Win 7 machine probably had not been configured for a remote SMTP server, so it  does not exists and your code line 170 was not syntaxically correct to create it.

    Author Comment

    Hi PDB,
    I am sure that's the problem but rather than encode the SMTP server in line 170, how can I configure it to work the same way it does on XP? The code I have seems to work on any standalone XP machine without a hitch (as long as the Outlook Express on that machine is configured to send/recieve e-mails via a valid account, even if the user never starts OE), making it easy to transfer. If I have to encode the SMTP server details in line 170 then it is far less portable.

    Author Comment

    BTW, I did a search through the registry on the XP and found where I think all the SMTP server settings have been written. How they got there I don't know and how to get my MS Access to recognise them. Does this help figure out what I need to do???
     "HKEY_CURRENT_USER\Software\Microsoft\Internet Account Manager\Accounts\00000001"
    LVL 38

    Expert Comment

    While I personally don't know of any way to "read" the mail server settings from the Registry, that is something I can certainly look into.  

    Idea......, there appears to be "standard" settings associated with each different mail server program dependent on the Email client software in use, as shown in this link:  
    so maybe you could use a "select case" and execute the applicable server construct dependent on the Client email software that is used.

    Author Comment

    Hi PDB, I wonder if you could help me understand a little about the above code that may help me figure out what is going on. I have a massive knowledge gap. Bear in mind that I borrowed and modified the code. Specifically the questions in bold
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")  '<<<Where do I find out more about the CDO Configuration object?
    iConf.Load -1    ' CDO Source Defaults ' <<< What is the significance of this?

    'The following code assigns values to these fields, however in my XP system (because the values are loaded by OE into the "CDO Configuration" the values are already there - I don't need to enter any values. In fact "iConf.Fields("").Value" even contains the email address. What I need is a way to load these values in Windows 7 and make them stick. Otherwise I will need to put code in my function that says something like:
    If Nz(Environ("ComputerName"), "xx") = "ROB4077") then ' Set the values
       With Flds
            .Item("") = 2
            .Item("") _
                                     = SMTPserver
            .Item("") = 25
       End With
    LVL 38

    Accepted Solution

    This link appears to be an excellent source of info about CDO and the CDO object model:
                                          (use the menu on the left side of your screen)

    This link (if I understand it correctly) may be the solution to your problem by providing a single remote server, changing just 2 lines of your code, and configuring CDO through a standard, free gMail (Google Email) server.
                                      (scroll down to the section that says "THE SOLUTION")
    LVL 38

    Expert Comment

    If you want to pursue changing the smtp mail settings in the Windows Registry using vba, this link will show you the how within allowable constraints:

    Author Closing Comment

    Sorry for the delay. I have a bad, bad cold that has put me out of commission for a couple of days. The info you provided will help me better understand the CDO Object library and see if I can find a more universal solution. Thanks for your kind assistance

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
    I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now