Fun with Email: VB6, CDO, MAPI, and a Remote Exchange Server  Hot PDF Print E-mail
Tag it:
Delicious
Furl it!
Digg
NewsVine
Reddit
YahooMyWeb
Technorati
Articles Reviews Visual Basic
Written by Larry Gomez   
Monday, 19 March 2007

{mos_sb_discuss:39}     

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.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 (" This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ", " This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ", "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
 mail.Send

 Set mail = Nothing

 If Err.Number <> 0 Then
  blnSendMail = False
 Else
  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.

Read more 


User reviews

There are no user reviews for this item.

Add new review




Powered by jReviews

Last Updated ( Sunday, 08 July 2007 )
 
< Prev   Next >