CDO Email Default Settings

R

Robbo

I have just bought a new computer with Windows 7 and I am having trouble
using the following CDO function to send an e-mail unless I include the
optional SMTP Server details. With XP, provided I configured Outlook Express
(OE), the settings were available to me and I didn't need to define the SMTP
Server. I understand OE writes the values to the following registry key:
"HKEY_CURRENT_USER\Software\Microsoft\Internet Account
Manager\Accounts\00000001". However with Windows 7 I can't use OE and I can't
figure out how to access the SMTP Server values. That means I can't test
software on my machine that is used on all the XP machines that need the
application. Can anyone tell me if there is a way to get these values loaded
and registered properly on a Windows 7 Machine? The funciton I use is as
follows:

Function CDOEmail(sTo As String, _
CC As String, _
BCC As String, _
Subject As String, _
TextBody As String, _
Attachment As String, _
Optional SMTPserver As String) As Boolean
Dim iMsg As Object
Dim iConf As Object
Dim sSender As String

10 On Error GoTo CDOEmail_Error

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

30 If Nz(gsStoreIdent, "") = "" Then
40 fLog "CDOEmail", "Initialiser launched because gsStoreIdent
was: " & gsStoreIdent
50 Initialiser
60 End If

70 sSender = DLookup("Email", "tblStores", "Ident = '" & gsStoreIdent
& "'")
80 sSender = Mid(sSender, 1, InStr(sSender, "@") - 1) & " <" &
sSender & ">"

90 Set iMsg = CreateObject("CDO.Message")
100 Set iConf = CreateObject("CDO.Configuration")

110 If Len(SMTPserver) > 0 Then
Dim Flds As Variant
120 iConf.Load -1 ' CDO Source Defaults
130 Set Flds = iConf.Fields
140 With Flds
150
..Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
160
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= SMTPserver
170
..Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
180 .Update
190 End With
200 End If

210 On Error Resume Next
220 With iMsg
230 Set .Configuration = iConf
240 .To = sTo
250 .CC = CC
260 .BCC = BCC
270 .FROM = sSender
280 .Subject = Subject
290 .TextBody = TextBody
300 If Dir(Attachment) <> "" And Attachment <> "" Then
310 .AddAttachment Attachment
320 End If
330 .Send

340 If Err.Number = -2147220973 Then
350 fLog "CDOEmail", "The transport failed to connect to the
server."
360 CDOEmail = 0
370 ElseIf Err Then
380 Stop
390 fLog "CDOEmail", "Email failed to send " & Err.Number & "
" & Err.Description
400 MsgBox "Error : " & Err.Number & " " & Err.Description & "
Please note the details of this message."
410 CDOEmail = 0
420 Else
430 CDOEmail = -1
440 End If
450 End With

460 On Error GoTo 0
470 fLog "CDOMail", "CDOEmail sequence finished normally"
480 Exit Function

CDOEmail_Error:

490 MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure CDOEmail of Module CDOMail"
Exit Function
Resume
End Function
 
G

GeoffG

Can anyone tell me if there is a way to get these
values loaded and registered properly on a
Windows 7 Machine?

I don't know the answer to the above question.
However, have you tried installing Windows Live Mail
(Outlook Express's successor)?

Geoff
 
P

Paul Shapiro

I think CDO has been on the way out for some time. It's no longer included
with Outlook 2007, but must be downloaded from MS. If requiring Outlook or
some other specified mail client is not an option for your users, you can
use Windows Virtual PC to create a Windows XP development environment on
your computer. Win 7 Professional and Ultimate include a license for a
pre-built (and licensed) Win XP virtual machine that can be downloaded from
MS. For other Win 7 versions I think Windows Virtual PC (the successor to
Virtual PC 2007) is still available, but you need a separate Win XP license
and you have to build the VM yourself. Either way it's a pretty simple setup
that gets you a Win XP environment for test and/or development. However,
this only helps until your first client upgrades to Win 7, when they don't
have any built-in mail client.

Another option is 3rd-party software that connects to a user-specified SMTP
server, but that probably requires more knowledge on the part of your users
since they will have to specify their own smtp server. It's certainly more
convenient to use the existing mail client.
 
M

Mark Andrews

I would recommend storing the SMTP server name and credentials (and any
other setting needed) in the database itself, or in your own defined
registry keys. You could have an optional routine that trys to read the
values from the registry (in case they are stored by another application) or
allow the user to enter them. I'm not sure of your organization's email
smtp server details. You could use one of the many smtp components to send
mail instead of relying on CDO. I like the Ostrosoft component because it
has some interaction to show what's happening when it tries to send the
email and returns error codes if needed.

Here's a little demo using the ostrosoft component:
http://www.rptsoftware.com/products/email/

SMTP components:
http://www.google.com/search?sourceid=navclient&ie=UTF-8&rlz=1T4GGLL_en&q=smtp+component

It looks like you are making life difficult for yourself using CDO. If you
must stay with CDO try this:
http://www.google.com/search?hl=en&rlz=1T4GGLL_en&q=install+cdo+on+windows+2007&aq=f&oq=&aqi=

HTH,
Mark Andrews
RPT Software
http://www.rptsoftware.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top