Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
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

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-----


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!


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

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.