MAPISendMessage, doesn't work on first try

This is a discussion on MAPISendMessage, doesn't work on first try within the C++ Programming forums, part of the General Programming Boards category; I made it work now, but it won't send on the first try. If i try again, it works fine.. ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    MAPISendMessage, doesn't work on first try

    I made it work now, but it won't send on the first try. If i try again, it works fine..
    Any suggestions?

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    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);
    }

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    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?

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I finally figured it out: You have have to memset the structures to 0 before use...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 11:50 AM
  2. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 11:39 PM
  3. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 05:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21