Using CDO for email

imaquila

Board Regular
Joined
Feb 4, 2012
Messages
86
I've found an example of the code but it triggers an error. "The "SendUsing" configuration value is invalid."
Since I did a copy and paste of the code changing on the the variable for the address to send to. I'm guessing that I do not have something installed which is needed to use CDO. I found and selected "Microsoft CDO for Win 2000" from my reference library (I have Win 7 but I thought it might work) but I got the same error. Maybe I need a line of code to link my project to the reference library. I'm not sure.

If I do need something else to use CDO what would it be?

My thanks to anyone who can help.
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I *think* the problem must be somewhere in the configuration. I now get the error "class not registered" on the line "Set Flds = iConf.Fields". I freely admit that I don't know anything about CDO and this is my first experience with trying to use it. I'm hoping someone can point out what I've overlooked.
Thanks,
Code:
Sub CDO_Mail_Small_Text()
    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")

     iConf.Load -1    ' CDO Source Defaults
     Set Flds = iConf.Fields
     With Flds
         .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
         .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "[COLOR=Green]smtp server address[/COLOR]"
         .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
         .Update
     End With
.
.
 
Upvote 0
you need to have a valid SMTP server address defined. You have copied in the dummy one that you need to replace. The SMTP server needs to be valid on the network you are connected to or a GMAIL smtp server.
 
Upvote 0
Thanks for taking the time to reply. I assume that you are referring to that part of the code that I made green and typed "smtp server address". The equivalent would be "smtp.frontier.com". Even so, I don't believe that would affect the error "class not registered". Any other ideas?
 
Upvote 0
Upvote 0
xenou,
Thanks for your post. While waiting for posts, I've been busy researching on line and I have changed the sendusing line to =1 (since I do not have Outlook Express or otherwise). I still have the same "class not registered" error before it even gets that far. I have found a number of other posts from others with the same error but I have not found one yet that mentions a solution. Because of the others who also had problems with "Class not registered" I have to wonder if maybe CDO is still looking for some element (maybe included in Outlook) even though Outlook is not fully used to send the mail.. Something clearly seems to be missing for some of us.

Initially I set up my email from Excel using ShellExecute instead of CDO but I've found that the data that I'm transferring to the email is truncated after about the first dozen records. (something like 1024 characters including spaces etc) That's why I was trying to find success with CDO. You mentioned that you no longer use CDO, does that mean that you're using some other Outlook based method for email or is there another alternative for me to explore that does not requite Outlook Express?

Thanks again for your help it IS appreciated.
 
Upvote 0
I would try following the example here (send a text email using a remote server):
http://www.paulsadowski.com/wsh/cdo.htm

You are creating a CDO configuration as a class but in the example the configuration is a property of the CDO message object, not a separate class. Does that work?

-----
Note:
I'm not sure if I employ sendusing = 1 or sendusing = 2 - I will have to look when I'm back a work. If you have outlook you can send emails that way too. These two have both worked for me. Email seems to get complicated but you can usually get them out one way or another.
 
Last edited:
Upvote 0
Re: Using CDO Class not Registered ERROR

I had tried an example from that page but the same error is triggered at the line:
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
 
Last edited:
Upvote 0
I thought your message object was iMsg, not objMessage. Are you using the right variable? Post the complete code to avoid confusion as I don't know how this snippet fits in now.
 
Upvote 0
Okay, I ran a test in Win7 (the same as I did once before, and it works fine). This is on a simple Desktop machine, using my ISP's smtp server. Nothing fancy in the email. At work you'd probably use your company's smtp server, which you can probably see in your outlook setup options - it's usually smtp.mycompany.com or mail.mycompany.com.

For your testing, I'd recommend early binding. This makes for easier and more accurate coding since you have access to object methods and properties with intellisense. It will also, incidentally, require to be sure you have the class library you need.

Code:
[COLOR="Navy"]Function[/COLOR] SendEmailCDO()
[COLOR="Navy"]Dim[/COLOR] objMessage [COLOR="Navy"]As[/COLOR] CDO.Message

    [COLOR="Navy"]On[/COLOR] [COLOR="Navy"]Error[/COLOR] [COLOR="Navy"]GoTo[/COLOR] ErrHandler:
    
    [COLOR="Navy"]Set[/COLOR] objMessage = [COLOR="Navy"]New[/COLOR] CDO.Message
    [COLOR="Navy"]With[/COLOR] objMessage
        
        .Subject = "Test [" & Now & "]"
        .From = "somebody [at] emailaddress.net"
        .To = "me [at] emailaddress.net"
        .TextBody = "This is a Test [" & Now & "]"
        
        .Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.east.cox.net"
        .Configuration.Fields.Item _
            ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Configuration.Fields.Update
                       
        .send
    
    [COLOR="Navy"]End[/COLOR] [COLOR="Navy"]With[/COLOR]
        
My_Exit:
[COLOR="Navy"]Set[/COLOR] objMessage = [COLOR="Navy"]Nothing[/COLOR]
[COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Function[/COLOR]

ErrHandler:
MsgBox Err.Description
[COLOR="Navy"]Resume[/COLOR] My_Exit

[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Function[/COLOR]


You want to be sure to reference the CDO library to use this code:
<img alt="image" src="http://northernocean.net/etc/mrexcel/20120415_references.jpg" />


In case anyone is wondering, most ISP's will cut you off if you tried to use something like this for sending spam from home (i.e., sending a *lot* of email) - that's why they require you to go through their smtp server when sending email from home. But it will work even from home if you are sending out a small number of emails from your machine -- I think this means something like 25 per day, but I'm not really sure.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top