Solved

MapiSendMail attachments don't display

Posted on 2014-03-27
14
663 Views
Last Modified: 2014-05-03
I'm using MapiSendMail to send email with a .PNG graphic file as an attachment. The email is delivered and received OK, but the .PNG file arrives as an attachment, not as a graphic displayed in the email body as I would like. The Microsoft documentation states that an attached file will simply display by default unless the nPosition member of the MapiFileDesc struct is -1.

The contents of the received email have something like this:

MIME-Version: 1.0
To: donald@pacificaresearch.com
Subject: Sales Invoice #107628 from Skyline Fluid Power, Inc
Content-Type: multipart/mixed;
 boundary="------------000505030408020502090309"

This is a multi-part message in MIME format.
--------------000505030408020502090309
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Your sales invoice #107628 from Skyline Fluid Power, Inc is attached.


--------------000505030408020502090309
Content-Type: image/png;
 name="email_107628.png"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="email_107628.png"

iVBORw0KGgoAAAANSUhEUgAACfYAAAzkCAIAAACYgxr+AAAABmJLR0QA/wD/AP+gvaeTAAAA
CXBIWXMAAC4jAAAuIwF4pT92AAAgAElEQVR4nOzd29ajKqIG0LhGvf8ruy/SlZ0yisgZnXP0
Ra/8igjGSvwCLOu6vgAAAAAAAACYwX+9KwAAAAAAAABALBEvAAAAAAAAwDREvAAAAAAAAADT
EPECAAAAAAAATEPECwAAAAAAADANES8AAAAAAADANES8AAAAAAAAANMQ8QIAAAAAAABMQ8QL
AAAAAAAAMA0RLwAAAAAAAMA0RLwAAAAAAAAA0xDxAgAAAAAAAExDxAsAAAAAAAAwDREvAAAA


The .PNG file is there. I think this is a clue:
Content-Disposition: attachment;

If I open an email dialog and drag the .PNG file into the body, I get something like this:

Content-Type: image/png;
 name="email_107628.png"
Content-Transfer-Encoding: base64
Content-ID: <part1.02020306.07010600@pacificaresearch.com>
Content-Disposition: inline;
 filename="email_107628.png"

iVBORw0KGgoAAAANSUhEUgAACfYAAAzkCAIAAACYgxr+AAAABmJLR0QA/wD/AP+gvaeTAAAA
CXBIWXMAAC4jAAAuIwF4pT92AAAgAElEQVR4nOzd29ajKqIG0LhGvf8ruy/SlZ0yisgZnXP0

where
Content-Disposition: inline;

seems to specify that the .PNG file should be displayed, not attached. How can I get MapiSendFile to put the .PNG file inline and not attached?
0
Comment
Question by:PacificaResearch
  • 6
  • 6
14 Comments
 
LVL 76

Expert Comment

by:arnold
Comment Utility
You're correct the Content-disposition is how the email client differentiates between something that it needs to render versus as an attachment.

I am not sure whether the means by which you code your app includes a method to alter/set the disposition setting in the construct from the defaulting attachment to inline.
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
You .....

http://msdn.microsoft.com/en-us/library/windows/desktop/dd296732(v=vs.85).aspx


If this is the language you use, there is a file description structure where you might be able to identify that a file is inline, while another is an attachment.
0
 

Author Comment

by:PacificaResearch
Comment Utility
The language is C++. The structs that you mention are initialized and set up according to Microsoft documentation. MapiSendMail clearly understands the file type:

Content-Type: image/png;
 name="email_107628.png"

The documentation for MapiFileDesc.nPosition states:

An integer used to indicate where in the message text to render the attachment. Attachments replace the character found at a certain position in the message text. That is, attachments replace the character in the MapiMessage structure field NoteText[nPosition]. A value of -1 (0xFFFFFFFF) means the attachment position is not indicated; the client application will have to provide a way for the user to access the attachment.

I've tried various values for nPosition, including integers from 0 to 10.
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
I do not believe the issue is with position specification.
You need to alter the Content-Disposition: entry.  I am uncertain what adds it. and whether it is defaulted when using mapistrattachment or something similar might be defaulting to attachment, unless a differnet set is selected.
0
 

Author Comment

by:PacificaResearch
Comment Utility
I don't find any documentation on a mapistrattachment() function. Is there such a thing?
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
I must have confused methods between ...

http://msdn.microsoft.com/en-us/library/windows/desktop/dd296732%28v=vs.85%29.aspx
are you using a list to enumerate the files and then filedesc
http://msdn.microsoft.com/en-us/library/windows/desktop/cc765770.aspx

instead of using a file path, see if you attach a datastream.

If you create a message:
text

attachment,

text

I think the structure listing the type of files should resolve the issue, though I seem to be drawing a blank on the reference .....
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:PacificaResearch
Comment Utility
I don't understand this reference:
are you using a list to enumerate the files and then filedesc
http://msdn.microsoft.com/en-us/library/windows/desktop/cc765770.aspx

The struct that defines the file type requires some kind of x.400 document type that Microsoft doesn't document in any understandable way. There example is something like "Microsoft Excel Spreadsheet".

 MapiSendMail already seems to understand the file type:

Content-Type: image/png;
 name="email_107628.png"
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
Agree, the X.400 is an ITU standard.
Though it is unclear how there are examples of someone using outlook API to generate a message using C++/VB and they set a parameter to a value.  

As you noted in your original question, the issue is how do you indicate that filea.png is an attachment versus fileb.png is an inline attachment via the control whether the Content-disposition is present and if it is how to control account for the value of inline or attachment.

Note that even if an image is attached and is marked as inline, the recipient still has control on whether images are to be displayed.
0
 

Author Comment

by:PacificaResearch
Comment Utility
So far, no answer to this question:

How do I get MapiSendMail to embed the attached .PNG file, as the Microsoft documentation clearly states it will do, automatically?

The Microsoft documentation is not ambiguous in any way about this. It states that the file will be rendered in the body of the email. That doesn't happen. Can it be made to happen? Does anyone have any experience with this? I receive emails every day with graphics embedded in them. Someone knows how to do this.
0
 
LVL 76

Expert Comment

by:arnold
Comment Utility
I've seen examples dealing the outlook API.
Unfortunately have not seen an example that fits your need, nor as you pointed out there is a clear example on the type x.400 designated that will solve the issue.
0
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility
The way I've done embedded images is to use a HTML body and at the point I want the image inserted, I add:

<img src="cid:MyImageID1">

Then add the attachment, and set it's content ID to:   "MyImageID1".

I also mark the attachment as hidden, and set the mail item to hide the paper clip.

Don't do that in C++ however, so I'm note sure if that helps or not.  Might get you pointed in the right direction though.

Jim.
0
 

Accepted Solution

by:
PacificaResearch earned 0 total points
Comment Utility
It appears that MapiSendMail does not perform as Microsoft has stated in their documentation. I will try some other method.
0
 

Author Closing Comment

by:PacificaResearch
Comment Utility
No expert was able to provide any solution or assistance. This may be because no expert has tried to use the MapiSendMail function, or Microsoft has not fixed bugs in the function.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now