Cóż ja mam funkcję napisaną w czystym C która wysyła wiadomość i wygląda ona tak:
#include <mapi.h>
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HWND hwndParent = NULL;
char* pszAttachPathname = "c:\\temp\\test.txt";
char* pszAttachFilename = "test.txt";
char* pszTo = "someone@example.com";
char* pszBody = "blah blah";
char* csSubject = "subject";
ULONG (PASCAL *lpfnMAPISendMail)(ULONG, ULONG, MapiMessage*, FLAGS, ULONG);
HMODULE hMAPI = LoadLibrary( "MAPI32.DLL" );
int nError = -1;
if ( hMAPI )
{
(FARPROC&)lpfnMAPISendMail = GetProcAddress(hMAPI,"MAPISendMail");
if ( lpfnMAPISendMail )
{
MapiMessage message;
MapiFileDesc filedesc;
MapiRecipDesc recip;
memset( &message, 0, sizeof(message) );
if ( pszAttachPathname )
{
ZeroMemory( &filedesc, sizeof(MapiFileDesc) );
filedesc.nPosition = (ULONG)-1;
filedesc.lpszPathName = pszAttachPathname;
filedesc.lpszFileName = pszAttachFilename;
message.nFileCount = 1;
message.lpFiles = &filedesc;
}
ZeroMemory( &recip, sizeof(MapiRecipDesc) );
recip.ulRecipClass = MAPI_TO;
recip.lpszName = pszTo;
message.nRecipCount = 1;
message.lpRecips = &recip;
message.lpszSubject = (char*)(LPCTSTR)csSubject;
message.lpszNoteText = pszBody;
// Bring up the send message dialog
nError = lpfnMAPISendMail(0, (ULONG)hwndParent, &message, MAPI_LOGON_UI|MAPI_DIALOG, 0);
}
FreeLibrary( hMAPI );
}
//return nError; // 0/SUCCESS_SUCCESS 1/MAPI_USER_ABORT, 11/MAPI_E_ATTACHMENT_NOT_FOUND
}
A problem wydaje mi się być w ustawianiu składowej recipClass
Szkoda, ze w screenie nie rozwinąłeś struktury recips. U mnie wygląda to następująco: