Why don't you just use Simple MAPI like this:
HINSTANCE hlibMAPI;
LPMAPISENDMAIL lpMAPISendMail;
MapiMessage msg;
MapiRecipDesc recipient, sender;
hlibMAPI = LoadLibrary("MAPI32.DLL");
if (!hlibMAPI)
{
AfxMessageBox("Error while sending E-Mail: Can't load MAPI32.DLL");
return;
}
lpMAPISendMail= (LPMAPISENDMAIL)GetProcAddress(hlibMAPI, "MAPISendMail");
if (!lpMAPISendMail)
{
AfxMessageBox("Error while sending E-Mail: Can't locate function 'MAPISendMail' in 'MAPI32.DLL'");
return;
}
long l = 123456;
unsigned long ul;
sender.ulReserved = NULL;
sender.ulRecipClass = MAPI_ORIG;
sender.lpszName = "generic";
sender.lpszAddress = "SMTP:generic@sender.org";
sender.ulEIDSize = 4;
sender.lpEntryID = &l;
recipient.ulReserved = NULL;
recipient.ulRecipClass = MAPI_TO;
recipient.lpszName = "dummy recipient";
char eadr[200];
strcpy(eadr, "SMTP:dummy@recipient.org");
recipient.lpszAddress = eadr;
recipient.ulEIDSize = 4;
recipient.lpEntryID = &l;
// setup message body
msg.ulReserved = NULL;
msg.lpszSubject = "sample subject";
msg.lpszNoteText = "sample text";
msg.lpszMessageType = NULL;
msg.lpszDateReceived = "2013/10/31 00:00";
msg.lpszConversationID = NULL;
msg.flFlags = MAPI_RECEIPT_REQUESTED;
msg.lpOriginator = &sender;
msg.nRecipCount = 1;
msg.lpRecips = &recipient;
msg.nFileCount = 0; /// <-- use this to attach your file
msg.lpFiles = NULL; //
ul = (*lpMAPISendMail)(NULL, (ULONG)AfxGetMainWnd(), &msg, MAPI_LOGON_UI, NULL);
FreeLibrary(hlibMAPI);
switch (ul)
{
case MAPI_E_LOGIN_FAILURE:
AfxMessageBox("Error while sending E-Mail: Coldn't login");
return;
case MAPI_E_INSUFFICIENT_MEMORY:
AfxMessageBox("Error while sending E-Mail: There was insufficient memory to send the e-mail");
return;
case MAPI_E_USER_ABORT:
AfxMessageBox("User canceled mail creation");
return;
case SUCCESS_SUCCESS:
AfxMessageBox("E-mail was sent successfully");
break;
default:
AfxMessageBox("Unknown error while sending E-Mail");
return;
}