title: C++ SimpleMAPI SendMail always fails?
body: <p>I am trying to use <a href="http://msdn.microsoft.com/en-us/library/dd296734(VS.85).aspx" rel="nofollow noreferrer">SimpleMAPI</a> to display a 'write message' dialogue with an attachment on Vista SP1 with either Windows Mail or Thunderbird in a C++ app (Borland C++ Builder 2006). I should be able to use <a href="http://msdn.microsoft.com/en-us/library/dd296721(VS.85).aspx" rel="nofollow noreferrer">MAPISendMail</a> to do this. </p>
  
  <p>I don't fill in a recipient address as I expect the user to do that when the mail client displays a 'write message' dialog. I also don't fill in an originator address as I expect the mail client to use the default. I have tried hardcoding them to see if thats the problem and it is not. </p>
  
  <p>My code looks like this:</p>
  
  <pre><code>HINSTANCE hMAPI;
  LPMAPISENDMAIL pSendMail;
  MapiMessage message;
  MapiFileDesc file;
  
  ZeroMemory( &amp;message, sizeof( MapiMessage ) );
  ZeroMemory( &amp;file, sizeof( MapiFileDesc ) );
  
  hMAPI = LoadLibraryA( "MAPI32.DLL" );
  
  pSendMail = (LPMAPISENDMAIL)GetProcAddress( hMAPI, "MAPISendMail" );
  
  // setup the attachment...
  file.nPosition     = -1;
  file.lpszPathName  = "C:\\my_attachment.dat";
  
  // set up the message...
  message.lpszSubject     = "My Subject";
  message.lpszNoteText    = "My Message...";
  message.lpszMessageType = "";
  message.nRecipCount     = 0;
  message.lpRecips        = NULL; // we don't know the recipient address(s)
  message.nFileCount      = 1;
  message.lpFiles         = &amp;file;
  message.lpOriginator    = NULL; // we don't know the users from address
  
  dwResult = pSendMail( lhSessionNull, (DWORD)Application-&gt;Handle, &amp;message, MAPI_LOGON_UI | MAPI_DIALOG, 0 );
  if( dwResult == SUCCESS_SUCCESS )
  { 
    // ...yay! :)
  }
  else
  {
    // ...we always fail here with: MAPI_E_FAILURE
  }
  </code></pre>
  
  <p>It always fails with error code 2 (MAPI_E_FAILURE). What am I doing wrong?</p>
  
  <p>Many thanks in advance.</p>