Link to home
Start Free TrialLog in
Avatar of error_prone
error_prone

asked on

CDO Question

Can someone give me a quick example on how to use CDO to send an email from either a macro or a button?  I'm using Outlook and Access 2007.  Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of error_prone
error_prone

ASKER

I'm testing the code below to send an email through a macro.  When I run the macro I don't receive an error, but I never receive the email either.
I'm running this on a company network.  Are there certain network settings that will prevent the email from sending but won't give me an error?


Public Function SendNotesMail()

Dim objEmail As Object
 On Error Resume Next
    Set objEmail = CreateObject("CDO.Message")
    objEmail.From = "me.me@mydomain.com"
    objEmail.To = "me.me@mydomain.com"
    objEmail.subject = "testing the subject"
    objEmail.TextBody = "testing the email body."
    'If strAttach <> "" Then objEmail.AddAttachment strAttach
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "something.something.exch"
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    objEmail.Configuration.Fields.Update
    objEmail.Send
    'If Err.Number <> 0 Then
 
    'Else
   
    'End If
    Set objEmail = Nothing

End Function
Here is a working example:

http://www.candace-tripp.net/download/emailcdo2k.zip

E-Mail to Multiple Recipients Using CDO Object
ends e-mail to multiple recipients using the CDO object (cdonts.dll)and stores the addresses in the database.
Says it's missing a reference to cdonts.dll.  How do I reference it?
I downloaded and registered the dll but when I try to send an email it says "Error. Message not delivered to selected recipeints."
Is there anything wrong with the example I posted above?
I even put a message box at the end of the code to see if it ran all the way through. I get the message box but never the email.
I took out the OnError line on the code I used above and am now receiving the following error:
The "SendUsing" configuration value is invalid.  How can I fix this?
SendUsing refers to the SMTP server that you're using. Are you absolutely sure that (a) you have a valid, configured SMTP server on the network and (b) you can send email in this fashion using the SMTP server? You'll have to ask your IT people about this, if you have any. If not, explain a little more about your network configuration - are you using Exchange for emails, for example? Are you using Outlook?

This article might help:
http://technet.microsoft.com/en-us/library/ee176585.aspx
Outlook 2007 and yes it's an Exchange server. Is there a way I can make sure if I'm using the right smtp server?