Home arrow Visual Basic arrow Fun with Email: VB6, CDO, MAPI, and a Remote Exchange Server

Fun with Email: VB6, CDO, MAPI, and a Remote Exchange Server

In this article, Matt shows us how to send emails from a VB Windows application. As CDONTS is for servers, a different approach must be used.

Author Info:
By: Matt Burnett
Rating: 4 stars4 stars4 stars4 stars4 stars / 82
February 16, 2003
  1. · Fun with Email: VB6, CDO, MAPI, and a Remote Exchange Server
  2. · The MAPI Approach
  3. · Conclusion

print this article

Fun with Email: VB6, CDO, MAPI, and a Remote Exchange Server
(Page 1 of 3 )

Yesterday, I was really unhappy with my computer. The programming at hand was clear and seemed to be a straightforward deal. In the end, it was not so easy.

The Deal: A client machine (workstation, Win98, 2000, or ME) will actively send emails from within a custom VB6 application (exe). Additionally, the application instantiated a custom local object (dll) that contained a public SendMail function with parameters to send the mail.

I stepped through this process by first (my machine is an NT workstation with transaction server):
  • Creating a VB form in MS Visual Basic 6 to hold the Click event and Public SendMail function.
  • Transfer the Public SendMail function to a class object.
  • Compile and run, calling the function from the class.
So easy (I thought!). I created a button to fire my SendMail function in the form (form1). I did not think that CDONTS is a server library and not available on other client types.

Private Sub Command1_Click()
 Call blnSendMail ("burnettm@hotmail.com", "burnettm@hotmail.com", "mail", "functional")
End Sub

Private Function blnSendMail(strTo As String, strFrom As String, strSubject As String, strBody As String) As Boolean
 'The CDO object is located on NT server, usually with the resource kit installed, ADCSRV4 is properly configured.
 On Error Resume Next
 Dim mail As CDONTS.NewMail
 Set mail = New CDONTS.NewMail

 mail.To = strTo
 mail.From = strFrom
 mail.Subject = strSubject
 mail.Body = strBody

 Set mail = Nothing

 If Err.Number <> 0 Then
  blnSendMail = False
  blnSendMail = True
 End If
End Function

Ok, so this script failed miserably when run on my workstation, but ran successfully on a server. However, this was not what I needed and I turned to MAPI. Now, MAPI is like an extended CDO object and is about having a ‘Profile’ setup in the "Inbox" on your computer. My next attempt, below, called a MAPI object in a VB form using an Inbox profile.
blog comments powered by Disqus

- Developing an XML Web Service Using Visual S...
- Creating an HTML File List with VB
- Fun with Email: VB6, CDO, MAPI, and a Remote...
- Extranet/Intranet Dictionary Cracker in VB
- Finding Default App Icons With Visual Basic
- Registry Fever With Visual Basic
- Implementing An ADO Data Control With VB6
- Printing With Visual Basic
- MSMQ Part 1/2: Architecture and Simple Imple...
- Magnifying The Desktop With Visual Basic
- Sending Email With MAPI Components in Visual...
- Two Person Chat With The Winsock Control And...
- A Real-Time ActiveX News Control
- Accessing the Windows API in Visual Basic

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials