Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MapiSendMail attachments don't display

Posted on 2014-03-27
14
Medium Priority
?
792 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
13 Comments
 
LVL 81

Expert Comment

by:arnold
ID: 39960634
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 81

Expert Comment

by:arnold
ID: 39960649
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
ID: 39962301
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 81

Expert Comment

by:arnold
ID: 39962633
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
ID: 39969823
I don't find any documentation on a mapistrattachment() function. Is there such a thing?
0
 
LVL 81

Expert Comment

by:arnold
ID: 39970935
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
 

Author Comment

by:PacificaResearch
ID: 39975815
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 81

Expert Comment

by:arnold
ID: 39975952
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
ID: 39989524
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 81

Expert Comment

by:arnold
ID: 39990186
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 58
ID: 40001397
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
ID: 40027841
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
ID: 40039020
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here in this article, you will get a step by step guidance on how to restore an Exchange database to a recovery database. Get a brief on Recovery Database and how it can be used to restore Exchange database in this section!
Steps to fix error: “Couldn’t mount the database that you specified. Specified database: HU-DB; Error code: An Active Manager operation fail”
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

810 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