Ssimple MAPI send with attachments inserts spaces


Mark Smith

I recently ran into a bizarre behavior with Outlook 2003 and 2007 (haven't
tested any others) and the Simple MAPI MAPISendMail function with attachments.

I'm creating a MapiMessage with only attachments in it. As long as there is
more than one attachment, for some reason the send mail dialog that pops up
has 2 spaces in the body for each attachment.

Here's the relevant code. count is the number of attachments:

MapiMessage *const pMsg = new MapiMessage;
ZeroMemory(pMsg, sizeof(MapiMessage));
pMsg->lpFiles = new MapiFileDesc[count];
ZeroMemory(pMsg->lpFiles, sizeof(MapiFileDesc) * count);

for (int i = 0; i < count; i++) {
CString filePath(...); // This is where the path to the attachment is
set - details are not relevant to this snippet
pMsg->lpFiles[pMsg->nFileCount].nPosition = -1;
pMsg->lpFiles[pMsg->nFileCount].lpszPathName = new
char[filePath.GetLength() + 1];
strcpy(pMsg->lpFiles[pMsg->nFileCount].lpszPathName, filePath);

if (AfxBeginThread(sendEmailThread, pMsg) == NULL) {

All the sendEmailThread does is call:

So the only somewhat odd thing going on here are that the MapiMessage is
created in one thread and sent on another. But I tried doing it all in the
same thread and it behaves the same.

As a test I tried setting the body to something other than NULL (I tried
both "" and "test") and in both cases I get the extra spaces plus a new line
before the specified text.

So, either this is a bug in Outlook (neither Outlook Express nor Windows
Mail do it) or I'm missing something. I looked through the flags for the
message itself and the MAPISendMail function and I didn't see anything that
seemed relevant.

The same behavior also occurs when doing a send to mail recipient in Windows
Explorer, which strongly suggests a bug in Outlook.

Any ideas?

Mark Smith


Jan 7, 2016
Reaction score
I had the same problem and found a solution. The problem is, if any file attachments have nPosition = -1, Outlook inserts a line above the message containing two spaces for each attachment where nPosition == -1. Also, if any nPosition is less than -1 or any two nPositions are equal, Outlook returns MAPI failure.

The solution is to set the nPosition of the first attachment to 0, the second to 1, and so on. This seems to get the exact outcome we would expect if they were all set to -1.

I haven't tested this with anything except Outlook 2010. Hopefully it doesn't mess up other clients.

It's worth mentioning that Windows' Send to > Mail recipient and every third party library's email functionality is also plagued by this annoyance when creating an email in Outlook.
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question