Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Send email using CDO Objects and Exchange Server

Posted on 2005-05-06
12
Medium Priority
?
3,530 Views
Last Modified: 2008-01-09
Hi,

I am trying to send email using CDO objects and Exchange server through VB. The code I am using is like this:

Private Sub Form_Load()
    'References added: Microsoft ADO 2.7 Library and Micrsoft CDO for Exchange 2000 Library

    Dim iMsg As New CDO.Message
    Dim iConf As New CDO.Configuration
    Dim Flds As ADODB.Fields
   
    Set Flds = iConf.Fields
   
    With Flds
        .Item(cdoSendUsingMethod) = cdoSendUsingExchange
        .Item(cdoSMTPServer) = "<exchange server ip address>"
       
        .Item(cdoSendUserName) = "<my username>"
        .Item(cdoSendPassword) = "<my password>"
       
        .Item(cdoSendEmailAddress) = "<my email address>"
       
        .Item(cdoURLProxyServer) = "<proxy server address:port>"'Proxy server is necessary as my machine is in another domain which is different than the exchange server domain.
        .Item(cdoURLProxyBypass) = "<local>"
       
        .Item(cdoURLGetLatestVersion) = True
       
        .Update
    End With
   
    Set iMsg.Configuration = iConf
   
    Set Flds = iMsg.Fields
   
    With Flds
        .Item(cdoTo) = "<my email address>"
        .Item(cdoFrom) = "<my email address>"
        .Item(cdoSender) = "<my email address>"
        .Item(cdoSubject) = "Check this stuff out."
        .Update
    End With
   
    With iMsg
        .HTMLBody = "Body"
        .Send
    End With
End Sub


I am getting error "Could not find the Sender's mailbox." at iMsg.Send method call.

Then referring some documentation online, I added this line
        .Item(cdo.cdoMailboxURL) = "file://./backofficestorage/<my exchange server domain name>/MBX/<my alias>"
before
        .Update

Now I am getting error "Object or data matching the name, range, or selection criteria was not found within the scope of this operation." at same method call

Do you have any idea how to resolve this issue?

Eventually I have to implement this code on a web page using ASP. Let me also know if there would be any problems in that.

Thanks for your time,
Nikhil
0
Comment
Question by:nikhil_628
  • 6
  • 4
11 Comments
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 13943730
try by setting this field aswell

            Flds.Fields(cdoSMTPAuthenticate) = cdoBasic


also make sure that ur Default SMTP Virtual Server is running ..

;-)
Shiju
0
 
LVL 1

Author Comment

by:nikhil_628
ID: 13943786
Added the authentication line, does not work even then.

Btw, the exchange server is running. I can access it via Outlook!
0
 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 13944442
ok
just for testing try this

           Flds.Item(cdoSendUsingMethod) = 1
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:Shiju Sasidharan
ID: 13944455
i mean ...

Flds.Item(cdoSendUsingMethod) = cdoSendUsingPickup
0
 
LVL 1

Author Comment

by:nikhil_628
ID: 13944594
Isn't cdoSendUsingPickup for sending emails using SMTP services on IIS?

Btw, I tried using cdoSendUsingPickup with cdoSMTPServerPickupDirectory = "c:\inetpub\mailroot\pickup". It created a email message in the directory. But I am not sure if that is what I need. I tried giving "file://./backofficestorage/<my exchange server domain name>/MBX/<my alias>/Inbox" as cdoSMTPServerPickupDirectory, but it gave error Path Not Found. (I am not running this code on exchange server!)

I even tried the third option cdoSendUsingPort. Now it gives error: The server rejected the sender address. The server response was: 454 5.7.3 Client does not have permission to Send As this sender.
0
 
LVL 1

Author Comment

by:nikhil_628
ID: 13944722
One more try:
Using cdoSMTPAuthenticate = cdoNTLM
I get the error:
The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available
0
 
LVL 18

Assisted Solution

by:Sethi
Sethi earned 375 total points
ID: 13949010
Why not use free VbSendMail component which is the best way to send emails:
http://www.freevbcode.com/ShowCode.Asp?ID=109
0
 
LVL 14

Accepted Solution

by:
Shiju Sasidharan earned 375 total points
ID: 13949485
nikhil_628 , u have made lots of chages here and there on ur code. can u please post the final code and point out where , in which line , u get error, and what type of error...
0
 
LVL 1

Author Comment

by:nikhil_628
ID: 13956744
Here is the changed code

Private Sub Form_Load()
    'References added: Microsoft ADO 2.7 Library and Micrsoft CDO for Exchange 2000 Library

    Dim iMsg As New CDO.Message
    Dim iConf As New CDO.Configuration
    Dim Flds As ADODB.Fields
   
    Set Flds = iConf.Fields
   
    With Flds
        .Item(cdoSendUsingMethod) = cdoSendUsingExchange
        .Item(cdoSMTPServer) = "<exchange server ip address>"
        .Item(cdoSMTPAuthenticate) = cdoBasic
       
        .Item(cdoSendUserName) = "<my username in format DOMAIN\USERNAME>"
        .Item(cdoSendPassword) = "<my password>"
       
        .Item(cdoSendEmailAddress) = "<my email address>"
        .Item(cdoMailboxURL) = "http://<exchange server IP address>/exchange/<my user name>"
       
        .Item(cdoURLProxyServer) = "<proxy server address:port>"'Proxy server is necessary as my machine is in another domain which is different than the exchange server domain.
        .Item(cdoURLProxyBypass) = "<local>"
       
        .Item(cdoURLGetLatestVersion) = True
       
        .Update
    End With
   
    Set iMsg.Configuration = iConf
   
    Set Flds = iMsg.Fields
   
    With Flds
        .Item(cdoTo) = "<my email address>"
        .Item(cdoFrom) = "<my email address>"
        .Item(cdoSender) = "<my email address>"
        .Item(cdoSubject) = "Check this stuff out."
        .Update
    End With
   
    With iMsg
        .HTMLBody = "Body"
        .Send
    End With
End Sub
0
 
LVL 1

Author Comment

by:nikhil_628
ID: 13956754
Error is "Object or data matching the name, range, or selection criteria was not found within the scope of this operation."
At the method call iMsg.Send.
0
 
LVL 1

Author Comment

by:nikhil_628
ID: 14463955
This stuff worked for me after a lot of permutation and combinations! --

thanks for your help!

Private Sub Form_Load()
    'References added: Microsoft ADO 2.7 Library and Micrsoft CDO for Exchange 2000 Library

    Dim iMsg As New CDO.Message
    Dim iConf As New CDO.Configuration
    Dim Flds As ADODB.Fields
   
    Set Flds = iConf.Fields
   
    With Flds
        .Item(cdoSendUsingMethod) = cdoSendUsingPort
        .Item(cdoSMTPServer) = "<exchange server ip address>"
        .Item(cdoSMTPAuthenticate) = cdoBasic
      .Item(cdoSMTPServerPort)  = 25
      .Item(cdoSMTPConnectionTimeout) = 10
       
        .Item(cdoSendUserName) = "<my username in format DOMAIN\USERNAME>"
        .Item(cdoSendPassword) = "<my password>"
       
        .Item(cdoSendEmailAddress) = "<my email address>"
        .Item(cdoMailboxURL) = "http://<exchange server IP address>/exchange/<my user name>"
       
        .Item(cdoURLProxyServer) = "<proxy server address:port>"'Proxy server is necessary as my machine is in another domain which is different than the exchange server domain.
        .Item(cdoURLProxyBypass) = "<local>"
       
        .Item(cdoURLGetLatestVersion) = True
       
        .Update
    End With
   
    Set iMsg.Configuration = iConf
   
    Set Flds = iMsg.Fields
   
    With Flds
        .Item(cdoTo) = "<my email address>"
        .Item(cdoFrom) = "<my email address>"
        .Item(cdoSender) = "<my email address>"
        .Item(cdoSubject) = "Check this stuff out."
        .Update
    End With
   
    With iMsg
        .HTMLBody = "Body"
        .Send
    End With
End Sub
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question