Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 27th, 2006, 03:14 AM
Authorized User
Join Date: Feb 2006
Location: , , Singapore.
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending Email from ADP using CDO

Hi guys...

Been trying to send e-mail using CDO 1.2.1 from my Access ADP project as I want to bypass MS Outlook. However, I am facing some AccessDenied error...

The error message is as stated:
[Collaboration Data Objects - [E_ACCESSDENIED(80070005)]]
Stepping through my code, the error is generated at the .Send Statement (see code below).

Any help is greatly appreciated. Thanks in advance.

Below is my code:

Private Sub CmdSendEmail_Click()
    Dim cdoSession As MAPI.Session
    Dim cdoFolder As MAPI.Folder
    Dim cdomessages As MAPI.Messages
    Dim cdomessage As MAPI.Message
    Dim cdoRecipient As MAPI.Recipient
    Dim cdoRecipients As MAPI.Recipients
    Set cdoSession = New MAPI.Session
    cdoSession.Logon "Outlook"

    Set cdoFolder = cdoSession.Outbox
    Set cdomessages = cdoFolder.Messages
    Set cdomessage = cdomessages.Add
    Set cdoRecipients = cdomessage.Recipients

    With cdomessage
        .Text = Me!txtMessage
        .Subject = "Issue Resolution"
        Set cdoRecipient = cdoRecipients.Add
        cdoRecipient.Name = "Scripts"
        cdoRecipient.Type = CdoTo
        cdoRecipient.Address = "SMTP:myMail@myMail.com"
        .Update '<- No problem here.
        .Send '<- This is where the error is generated

    End With

    Set cdoSession = Nothing

End Sub

Reply With Quote
  #2 (permalink)  
Old March 29th, 2006, 08:49 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

That code looks like you are going through Outlook, not avoiding it. Here is generic code to avoid outlook.

'-----Code Starts-----
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Sample Subject"
objMessage.Sender = "alias@yourdomain.com"
objMessage.To = strRecipient
objMessage.TextBody = "Message text"

'==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") = "mail.yourdomain.com"

'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") = "****"

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

'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


'==End remote SMTP server configuration section==
'-----Code Ends-----


Reply With Quote
  #3 (permalink)  
Old March 29th, 2006, 10:50 AM
Authorized User
Join Date: Feb 2006
Location: , , Singapore.
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks mmcdonal
Think what you are using is the CDOEX.dll Library right?
Made a switch to that yesterday and its working...
Code is as what you have.

Thanks Nevertheless!

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
CDO Email error Treefarn Classic ASP Professional 10 February 20th, 2007 02:39 PM
CDO email BananaJim Classic ASP Professional 6 January 27th, 2007 08:04 PM
error sending email with attachment using CDO archanahs Classic ASP Professional 1 May 25th, 2006 08:16 AM

All times are GMT -4. The time now is 09:30 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.