The following Simple MAPI sample will add a message to the outbox of OE or whatever email client has installed itself as the default MAPI client. A security dialog will be shown before the message is sent. There are a couple of email samples here. They require the DispHelper library.
Code:
#include <windows.h>
#include <mapi.h>
#include <stdio.h>
ULONG xSendEmail(PSTR szSubject, PSTR szMessage, PSTR szRecipient)
{
HMODULE hMapi = NULL;
LPMAPISENDMAIL pMAPISendMail = NULL;
MapiMessage msg = { 0 };
MapiRecipDesc recip = { 0 };
recip.ulRecipClass = MAPI_TO;
recip.lpszAddress = szRecipient;
msg.lpszSubject = szSubject;
msg.lpszNoteText = szMessage;
msg.nRecipCount = 1;
msg.lpRecips = &recip;
hMapi = LoadLibrary(TEXT("mapi32.dll"));
if (hMapi)
{
pMAPISendMail = (LPMAPISENDMAIL) GetProcAddress(hMapi, "MAPISendMail");
if (pMAPISendMail)
{
return pMAPISendMail(0, 0, &msg, 0, 0);
}
FreeLibrary(hMapi);
}
return ERROR_INVALID_DLL;
}
int main(void)
{
ULONG ret = xSendEmail("Test Message", "Hello world!\r\nThis is a test.", "[email protected]");
if (ret == SUCCESS_SUCCESS)
{
printf("Success!\n");
}
else
{
printf("Failed with error code %d.\n", ret);
}
getchar();
return 0;
}