Microsoft KB Archive/171098: Difference between revisions
From BetaArchive Wiki
m (Text replacement - "<" to "<") |
m (Text replacement - "&" to "&") |
||
(2 intermediate revisions by the same user not shown) | |||
Line 55: | Line 55: | ||
== MORE INFORMATION == | == MORE INFORMATION == | ||
Before compiling and running the following code, be sure to follow the instructions given wherever the text | Before compiling and running the following code, be sure to follow the instructions given wherever the text "TO DO:" is found. | ||
=== Sample Code === | === Sample Code === | ||
Line 65: | Line 65: | ||
// TO DO: If you are using Active Messaging 1.0 or 1.0a, | // TO DO: If you are using Active Messaging 1.0 or 1.0a, | ||
// unremark the following line: | // unremark the following line: | ||
// #import <mdisp32.tlb | // #import <mdisp32.tlb> no_namespace | ||
// mdisp32.tlb is in \winnt\system32 on Windows NT or | // mdisp32.tlb is in \winnt\system32 on Windows NT or | ||
// \Win95\System directory on Windows 95 when Exchange is installed. | // \Win95\System directory on Windows 95 when Exchange is installed. | ||
Line 71: | Line 71: | ||
// TO DO: If you are using Active Messaging 1.1, | // TO DO: If you are using Active Messaging 1.1, | ||
// unremark the following line: | // unremark the following line: | ||
// #import <olemsg32.dll | // #import <olemsg32.dll> no_namespace | ||
// olemsg32.dll is in \winnt\system32 on Windows NT or | // olemsg32.dll is in \winnt\system32 on Windows NT or | ||
// \Win95\System directory on Windows 95 when Exchange is installed. | // \Win95\System directory on Windows 95 when Exchange is installed. | ||
Line 77: | Line 77: | ||
// TO DO: If you are using CDO 1.2 or 1.2.1, unremark the | // TO DO: If you are using CDO 1.2 or 1.2.1, unremark the | ||
// following line: | // following line: | ||
// #import <cdo.dll | // #import <cdo.dll> no_namespace | ||
// cdo.dll is in \winnt\system32 on WinNT or | // cdo.dll is in \winnt\system32 on WinNT or | ||
// \Win95\System directory on Win95 w/Exchange is installed. | // \Win95\System directory on Win95 w/Exchange is installed. | ||
// TO DO: If you are using CDO (1.0, 1.0a) unremark the next line: | // TO DO: If you are using CDO (1.0, 1.0a) unremark the next line: | ||
// #import <mdisp32.tlb | // #import <mdisp32.tlb> no_namespace | ||
// mdisp32.tlb is in \winnt\system32 on Windows NT or | // mdisp32.tlb is in \winnt\system32 on Windows NT or | ||
// \Win95\System directory on Windows 95 when Exchange is installed. | // \Win95\System directory on Windows 95 when Exchange is installed. | ||
// TO DO: If you are using CDO (1.1) unremark the next line: | // TO DO: If you are using CDO (1.1) unremark the next line: | ||
// #import <olemsg32.dll | // #import <olemsg32.dll> no_namespace | ||
// olemsg32.dll is in \winnt\system32 on Windows NT or | // olemsg32.dll is in \winnt\system32 on Windows NT or | ||
// \Win95\System directory on Windows 95 when Exchange is installed. | // \Win95\System directory on Windows 95 when Exchange is installed. | ||
// TO DO: If you are using CDO (1.2, 1.21) unremark the next line: | // TO DO: If you are using CDO (1.2, 1.21) unremark the next line: | ||
// #import <cdo.dll | // #import <cdo.dll> no_namespace | ||
// cdo.dll is in \winnt\system32 on WinNT or | // cdo.dll is in \winnt\system32 on WinNT or | ||
// \Win95\System directory on Win95 w/Exchange is installed. | // \Win95\System directory on Win95 w/Exchange is installed. | ||
#include <stdio.h | #include <stdio.h> | ||
#include <assert.h | #include <assert.h> | ||
#include <tchar.h | #include <tchar.h> | ||
void dump_com_error(_com_error & | void dump_com_error(_com_error &e) | ||
{ | { | ||
_tprintf(_T( | _tprintf(_T("Oops - hit an error!\n")); | ||
_tprintf(_T( | _tprintf(_T("\a\tCode = %08lx\n"), e.Error()); | ||
_tprintf(_T( | _tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage()); | ||
_bstr_t bstrSource(e.Source()); | _bstr_t bstrSource(e.Source()); | ||
_bstr_t bstrDescription(e.Description()); | _bstr_t bstrDescription(e.Description()); | ||
_tprintf(_T( | _tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource); | ||
_tprintf(_T( | _tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription); | ||
} | } | ||
Line 126: | Line 126: | ||
// TO DO: Create a MAPI.Session pointer | // TO DO: Create a MAPI.Session pointer | ||
// For CDO (1.0, 1.0a, 1.1) uncomment the next line | // For CDO (1.0, 1.0a, 1.1) uncomment the next line | ||
// SessionPtr pSession( | // SessionPtr pSession("MAPI.Session"); | ||
// For CDO (1.2, 1.21) uncomment the next line | // For CDO (1.2, 1.21) uncomment the next line | ||
// _SessionPtr pSession( | // _SessionPtr pSession("MAPI.Session"); | ||
// Logon using the specified profile | // Logon using the specified profile | ||
pSession- | pSession->Logon("TO DO: Place profile name here"); | ||
// Create pointer to the Outbox Folder | // Create pointer to the Outbox Folder | ||
FolderPtr pFolder = pSession- | FolderPtr pFolder = pSession->Outbox; | ||
// Create pointer to the Messages Collection | // Create pointer to the Messages Collection | ||
MessagesPtr pMessages = pFolder- | MessagesPtr pMessages = pFolder->Messages; | ||
// Create pointer to a new Message | // Create pointer to a new Message | ||
MessagePtr pMessage = pMessages- | MessagePtr pMessage = pMessages->Add(); | ||
// Set the Subject of the message | // Set the Subject of the message | ||
pMessage- | pMessage->Subject = "VCCOM: MAPI Example"; | ||
// Set the Text of the message | // Set the Text of the message | ||
pMessage- | pMessage->Text = "This is my message text."; | ||
// Create pointer to Attachments collection | // Create pointer to Attachments collection | ||
AttachmentsPtr pAttachments = pMessage- | AttachmentsPtr pAttachments = pMessage->Attachments; | ||
// Create new Attachment | // Create new Attachment | ||
// TO DO: Change the absolute path (which must be used) | // TO DO: Change the absolute path (which must be used) | ||
pAttachments- | pAttachments->Add("Mapi example source code.txt", 15000L, | ||
(long) mapiFileData, | (long) mapiFileData, | ||
"c:\\mapitest\\commail\\commail.cpp"); | |||
// Create pointer to Recipients Collection | // Create pointer to Recipients Collection | ||
RecipientsPtr pRecipients = pMessage- | RecipientsPtr pRecipients = pMessage->Recipients; | ||
// Create pointer to a new Recipient | // Create pointer to a new Recipient | ||
RecipientPtr pRecipient = pRecipients- | RecipientPtr pRecipient = pRecipients->Add(); | ||
// Set properties of the new recipient | // Set properties of the new recipient | ||
pRecipient- | pRecipient->Name = "TO DO: Place email alias here"; | ||
// Type can be ActMsgTo, mapiTo or CdoTo for different CDO versions | // Type can be ActMsgTo, mapiTo or CdoTo for different CDO versions | ||
// They all have constant value of 1. | // They all have constant value of 1. | ||
pRecipient- | pRecipient->Type = (long) mapiTo; | ||
// Resolve the recipient address | // Resolve the recipient address | ||
pRecipient- | pRecipient->Resolve(); | ||
_tprintf(_T( | _tprintf(_T("Sending message to %s.\n"), | ||
(LPCTSTR) (bstr_t) pRecipient- | (LPCTSTR) (bstr_t) pRecipient->Name); | ||
// Send the message | // Send the message | ||
pMessage- | pMessage->Send(false, false); | ||
// Logoff of the MAPI Session | // Logoff of the MAPI Session | ||
pSession- | pSession->Logoff(); | ||
} | } | ||
catch (_com_error & | catch (_com_error &e) | ||
{ | { | ||
dump_com_error(e); | dump_com_error(e); |
Latest revision as of 12:29, 21 July 2020
Article ID: 171098
Article Last Modified on 5/9/2005
APPLIES TO
- Microsoft Collaboration Data Objects 1.0
- Microsoft Collaboration Data Objects 1.0a
- Microsoft Collaboration Data Objects 1.1
- Microsoft Collaboration Data Objects 1.2
- Microsoft Collaboration Data Objects 1.21
This article was previously published under Q171098
SUMMARY
This article gives sample code written in Visual C++ that may be used to send a message with CDO (1.x). This sample is based on the code provided with the Microsoft Visual C++ 5.0 COMMAIL sample project.
MORE INFORMATION
Before compiling and running the following code, be sure to follow the instructions given wherever the text "TO DO:" is found.
Sample Code
/**********************************************************/ // COMMAIL.CPP // This program sends a message with an attachment /**********************************************************/ // TO DO: If you are using Active Messaging 1.0 or 1.0a, // unremark the following line: // #import <mdisp32.tlb> no_namespace // mdisp32.tlb is in \winnt\system32 on Windows NT or // \Win95\System directory on Windows 95 when Exchange is installed. // TO DO: If you are using Active Messaging 1.1, // unremark the following line: // #import <olemsg32.dll> no_namespace // olemsg32.dll is in \winnt\system32 on Windows NT or // \Win95\System directory on Windows 95 when Exchange is installed. // TO DO: If you are using CDO 1.2 or 1.2.1, unremark the // following line: // #import <cdo.dll> no_namespace // cdo.dll is in \winnt\system32 on WinNT or // \Win95\System directory on Win95 w/Exchange is installed. // TO DO: If you are using CDO (1.0, 1.0a) unremark the next line: // #import <mdisp32.tlb> no_namespace // mdisp32.tlb is in \winnt\system32 on Windows NT or // \Win95\System directory on Windows 95 when Exchange is installed. // TO DO: If you are using CDO (1.1) unremark the next line: // #import <olemsg32.dll> no_namespace // olemsg32.dll is in \winnt\system32 on Windows NT or // \Win95\System directory on Windows 95 when Exchange is installed. // TO DO: If you are using CDO (1.2, 1.21) unremark the next line: // #import <cdo.dll> no_namespace // cdo.dll is in \winnt\system32 on WinNT or // \Win95\System directory on Win95 w/Exchange is installed. #include <stdio.h> #include <assert.h> #include <tchar.h> void dump_com_error(_com_error &e) { _tprintf(_T("Oops - hit an error!\n")); _tprintf(_T("\a\tCode = %08lx\n"), e.Error()); _tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage()); _bstr_t bstrSource(e.Source()); _bstr_t bstrDescription(e.Description()); _tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource); _tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription); } // If this is placed in the scope of the smart pointers, they must be // explicitly Release(d) before CoUninitialize() is called. If any // reference count is non-zero, a protection fault will occur. struct StartOle { StartOle() { CoInitialize(NULL); } ~StartOle() { CoUninitialize(); } } _inst_StartOle; void main() { try { // TO DO: Create a MAPI.Session pointer // For CDO (1.0, 1.0a, 1.1) uncomment the next line // SessionPtr pSession("MAPI.Session"); // For CDO (1.2, 1.21) uncomment the next line // _SessionPtr pSession("MAPI.Session"); // Logon using the specified profile pSession->Logon("TO DO: Place profile name here"); // Create pointer to the Outbox Folder FolderPtr pFolder = pSession->Outbox; // Create pointer to the Messages Collection MessagesPtr pMessages = pFolder->Messages; // Create pointer to a new Message MessagePtr pMessage = pMessages->Add(); // Set the Subject of the message pMessage->Subject = "VCCOM: MAPI Example"; // Set the Text of the message pMessage->Text = "This is my message text."; // Create pointer to Attachments collection AttachmentsPtr pAttachments = pMessage->Attachments; // Create new Attachment // TO DO: Change the absolute path (which must be used) pAttachments->Add("Mapi example source code.txt", 15000L, (long) mapiFileData, "c:\\mapitest\\commail\\commail.cpp"); // Create pointer to Recipients Collection RecipientsPtr pRecipients = pMessage->Recipients; // Create pointer to a new Recipient RecipientPtr pRecipient = pRecipients->Add(); // Set properties of the new recipient pRecipient->Name = "TO DO: Place email alias here"; // Type can be ActMsgTo, mapiTo or CdoTo for different CDO versions // They all have constant value of 1. pRecipient->Type = (long) mapiTo; // Resolve the recipient address pRecipient->Resolve(); _tprintf(_T("Sending message to %s.\n"), (LPCTSTR) (bstr_t) pRecipient->Name); // Send the message pMessage->Send(false, false); // Logoff of the MAPI Session pSession->Logoff(); } catch (_com_error &e) { dump_com_error(e); } }
REFERENCES
For additional information about the CDO (1.x) Libraries, see the following article in the Microsoft Knowledge Base:
171440 INFO: Where to Acquire the CDO (all versions) Libraries
Keywords: kbhowto kbmsg kbcode KB171098