Solved

MapiSendMail attachments don't display

Posted on 2014-03-27
14
704 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 77

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 77

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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 77

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 77

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 77

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 77

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 57
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

791 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