1 Fun with Email: VB6, CDO, MAPI, and a Remote Exchange Server
2 The MAPI Approach
3 Conclusion
| Fun with Email: VB6, CDO, MAPI, and a Remote Exchange Server
(Page 1 of 3 )
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 ("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 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.
|