I made it work now, but it won't send on the first try. If i try again, it works fine..
Any suggestions?
Printable View
I made it work now, but it won't send on the first try. If i try again, it works fine..
Any suggestions?
Here's the code for the function:
Code:int DLLEXPORT CALLBACK sendMail(unsigned long hWnd, char *achSubj, char *achRec, char *achSender, char *achAttPath){
unsigned long lRes;
char dt[9], dateBuf[11];
MapiMessage *msg = new MapiMessage();
MapiRecipDesc *msgAvs = new MapiRecipDesc[1], *msgMott = new MapiRecipDesc[1];
MapiFileDesc *msgFile = new MapiFileDesc();
HINSTANCE h1;
F1 SendMail;
_strdate(dt);
dt[2]='\0';dt[5]='\0';
sprintf(dateBuf,"20%s.%s.%s", dt+6, dt, dt+3);
// Link MAPI32
if((h1 = LoadLibrary("Mapi32"))==NULL)
return(1); // Couldn't link to Mapi32
//typedef unsigned long (CALLBACK *F1)(LHANDLE lhSession, ULONG ulUIParam, lpMapiMessage lpMessage, FLAGS flFlags, ULONG ulReserved);
if(!(SendMail = (F1)GetProcAddress(h1, "MAPISendMail"))){
FreeLibrary(h1);
return(2);
}
// Fill Originator struct
msgAvs->ulReserved = 0;
msgAvs->ulRecipClass = MAPI_ORIG;
msgAvs->lpszName = achSender;
msgAvs->lpszAddress = achSender;
msgAvs->lpEntryID = NULL;
msgAvs->ulEIDSize = 0;
// Fill recipient struct
msgMott->ulReserved = 0;
msgMott->ulRecipClass = MAPI_TO;
msgMott->lpszName = achRec;
msgMott->lpszAddress = achRec;
msgMott->lpEntryID = NULL;
msgMott->ulEIDSize = 0;
// Fill file struct
msgFile->ulReserved = 0;
msgFile->flFlags = 0;
msgFile->nPosition = 0xFFFFFFFF;
msgFile->lpszPathName = achAttPath; // Path\filnavn
msgFile->lpFileType = NULL;
// Fill messageStruct
msg->ulReserved=0;
msg->lpszSubject = achSubj;
msg->lpszNoteText = NULL;
msg->lpszMessageType = NULL;
msg->lpszDateReceived = dateBuf;
msg->lpszConversationID = "";
msg->flFlags = MAPI_SENT;
msg->lpOriginator = msgAvs;
msg->nRecipCount = 1;
msg->lpRecips = msgMott;
msg->nFileCount = 1;
msg->lpFiles = msgFile;
lRes = SendMail(NULL, hWnd, msg, MAPI_LOGON_UI, 0);
delete msgAvs;
delete msgMott;
delete msgFile;
delete msg;
FreeLibrary(h1);
return((int)lRes);
}
lRes=11, but the attachment exists, i've checked it.
There's no difference between the first/second call, so i figured there was some initialization missing..?
Also, how can i send it directly without starting Outlook?
I finally figured it out: You have have to memset the structures to 0 before use...