Microsoft KB Archive/200150

= How to call a Visual Basic ActiveX DLL to send mail =

Article ID: 200150

Article Last Modified on 7/19/2005

-

APPLIES TO


 * Microsoft Collaboration Data Objects 1.1
 * Microsoft Collaboration Data Objects 1.2
 * Microsoft Collaboration Data Objects 1.21

-



This article was previously published under Q200150



SUMMARY
This article shows how to write a Visual Basic ActiveX DLL to send an e-mail message using Collaboration Data Objects (1.1, 1.2, 1.21). It also shows how to call this DLL from C code.



MORE INFORMATION
Use the following steps to create a Microsoft Visual Basic ActiveX DLL Project:  Open a new Visual Basic ActiveX DLL Project. Save the Project as Project2 and the Class as Class1. Make sure that the Name property in the Properties section of the project is also Project2. Make sure your project has a reference to Microsoft CDO (1.1, 1.2, 1.21) Library.  Place the following code in a class module in Project2. Public Function sendmail(Recip As String, Subject As String) Dim osession As MAPI.Session Dim omessage As Message Dim oRecip As Recipient Set osession = CreateObject("MAPI.Session") osession.Logon Set omessage = osession.Outbox.Messages.Add omessage.Subject = Subject Set oRecip = omessage.Recipients.Add(Recip) oRecip.Resolve omessage.Text = "Testing" omessage.Send, True osession.Logoff End Function

The following C code (Win 32 Application) is used to create and call the ActiveX DLL. // activexdll1.cpp : Defines the entry point for the application. //


 * 1) include "stdafx.h"
 * 2) include 

// Change to include your DLL


 * 1) import "Project2.dll" no_namespace

int APIENTRY WinMain(HINSTANCE hInstance,                    HINSTANCE hPrevInstance,                     LPSTR     lpCmdLine,                     int       nCmdShow) {

// Initialize COM

CoInitialize(NULL);

// Change to the name of the person // you wish to send the message

_variant_t name ("alias"); _variant_t subject ("Testing ActiveX DLL"); // Create an instance of the ActiveX object // Where Class1 is the class module of your Project2 _Class1Ptr oDLL("Project2.Class1");

oDLL->sendmail(&name.bstrVal,&subject.bstrVal); oDLL = NULL; CoUninitialize; return 0; }                   

Keywords: kbhowto kbmsg kbfaq KB200150

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.