Re: How to replace an attachment from a file.wav to a winmail.dat



Hi Dmitry,

As you know, we succeeded to convert the .wav attachment into winmail.dat
and also sending the modified e-mail to it's destiny. But we faced one
problem: the machine that this DLL will be installed does not have Outlook
installed on. And it will not have Outlook installed on.
Due to this, when the code tries to convert back from MAPI to MIME using the
API IConverterSession:MAPItoMIMEStm, on that machine we get the
MAPI_E_BAD_CHARWIDTH error.
We tried to install and register the OUTLMIME.DLL, but it was not enough. I
believe than that this issue has two possible solutions: the first would be
to install the Outlook on this machine, and the second one would be to
implement manually the IConverterSession. Otherwise, there is no other way.
Is this correct ? And if it is, how complex this implementation can be ?

"Dmitry Streblechenko" wrote:

Hard to say without seeing teh actual code, but do you release the
attachment tabel and every attachment before calling MAPIToMIMEStm?
IMessage created on top of an MSG file won't let you reopen the attachment
table while an old one is still alive.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Rodrigo Mendes" <RodrigoMendes@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:01E05F48-C801-4F1A-B061-688FF36BAD58@xxxxxxxxxxxxxxxx
Hi Dmitry.

I've made some progress on this, but I'm stuck in another part of the
solution.

This is what I've made so far:

1) we copied the contents of the received e-mail into a file, using the
pMailMsg->CopyContentToFileAtOffset method.

2) we created one stream object with the contents of the file using the
OpenStreamOnFile function.

3) After that, we created a storage with StgCreateStorageEx function.

4) And then, we can use the OpenIMsgOnIStg function that you mentioned.

5) we converted the contents of the stream to the IMessage using the
IConverterSession:MIMEtoMAPI

6) we got the attachment list using functions GetAttachmentTable,
HrQueryAllRows, and using the OpenAttach function, I verified if there is
an
attachment to be handled.

7) using the DeleteAttach function, I deleted the old attachment

8) using the CreateAttach function, I created the new attachment

9) then I setted the following props:
props[0].ulPropTag = PR_ATTACH_TRANSPORT_NAME;
props[0].Value.lpszA = pszWinmail;

props[1].ulPropTag = PR_ATTACH_LONG_FILENAME;
props[1].Value.lpszA = pszWinmail;

props[2].ulPropTag = PR_ATTACH_FILENAME;
props[2].Value.lpszA = pszWinmail;

props[3].ulPropTag = PR_MESSAGE_CLASS;
props[3].Value.lpszA = pszMessageClass;

hr = lpDstAttach->SetProps(4, props, NULL);

10) after that, we opened a new stream using the OpenProperty function

11) and we created the new tnef stream using the OpenTnefStreamEx

12)we added the props to this tnef using the pTnef->AddProps function

13) we finished this tnef using pTnef->Finish

14) we committed the new stream pStrmDst->Commit

15) we saved the changes into the new attachment
lpDstAttach->SaveChanges(KEEP_OPEN_READWRITE);

16) and saved also the changes into the IMessage
pIMsg->SaveChanges(KEEP_OPEN_READWRITE)

17) and then, when I try to convert back to MIME using
pConverterSession->MAPIToMIMEStm(pIMsg, pStreamFileOut,
CCSF_SMTP)))
I got an error (E_ACCESSDENIED). This error on this conversion only
happens
if the ConverterSession is placed after the SaveChanges from the new
Attach.

Can you help me ?

Thanks in advance one more time,
Rodrigo




"Dmitry Streblechenko" wrote:

Do you mean you have a stream with the MIME contents that you need to
import
into IMessage>
Extended MAPI knows nothing about MIME. You can use IConverterSession to
convert MIME to MAPI if you have Outlook 2002 or higher installed (can't
do
that on an Exchange server machine) or you will nee to write your own
parser
to parse the MIME message and set the corresponding MAPI properties one
property at a time.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Rodrigo Mendes" <RodrigoMendes@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
news:7355F8E1-D903-4228-8723-1B976A6A92F6@xxxxxxxxxxxxxxxx
Hi again Dmitry,

Let me ask you some more things related to this subject.

We've made some progress, and now were stuck in another place.

Let me write what we have done so far:

First, we copied the contents of the received e-mail into a file, using
the
pMailMsg->CopyContentToFileAtOffset method.

Then, we created one stream object with the contents of the file using
the
OpenStreamOnFile function.

After that, we created a storage with StgCreateStorageEx function.
And then, we can use the OpenIMsgOnIStg function that you mentioned.

But we have a problem. Between the OpenStreamOnFile function and the
StgCreateStorageEx function, we need to copy the contents of the
IStream
into the IMessage interface.

We tried to use the HrIStorageFromStream function, but it only works
for
reading. And we need to manipulate it.

Do you have any suggestion on this ?

Thanks one more time.

"Rodrigo Mendes" wrote:

Well, I'm not allowed to say in details due to confidentiality
matters,
but
my customer integrates on his solution the email programs that
everybody
uses
(lets say, email program "A", which deals with regular MIME format)
with
the
MS Exchange 2003, which deals with TNEF format. They will have to
encapsulate
the .wav files that program "A" attaches into TNEF format in order to
MS
Exchange receive it as a "regular" winmail.dat attachment.

Thanks for your help so far.

"Dmitry Streblechenko" wrote:

I am still curious why your customer needs - the real attachment
woudl
still
need to be extracted.
One way to get IMessage is to create a temporary MSG file using
OpenIMsgOnIStg.
Yes, you would need to construct the TNEF data one byte at a time.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Rodrigo Mendes" <RodrigoMendes@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
news:28036153-20BD-4787-B5DA-AE22E50CD2EA@xxxxxxxxxxxxxxxx
Hi Dmitry,

I'm doing this because the customer of the project that I'm
working
for
needs this solution.
Concerning the Extended MAPI, I was aware that this could be the
solution
for it, but I'm stuck in this problem - to get the information
(the
mail
attachment) from the MailMsg interface (which is the only one that
I
found
out to access the e-mail contents after using the
OnMessageSubmission
method)
and making it available for the IMessage or the Extended MAPI
interfaces.

And about the winmail.dat, once I convert it to TNEF format, I
guess
I'll
have to handle those properties in some other way. When you say
construct
the TNEF stream explicitly in my code, you mean open the file that
I'm
able
to save (using the CopyContentToFileEx method) and converting it
byte per
byte "by hand" ?

"Dmitry Streblechenko" wrote:

You would need to use Extended MAPI for that.
Or you could construct the TNEF stream epxlicitly in your code,
its
format
is documented.
Keep in mind than winmail.dat is not an attachment wrapper, it
contains
properties (MAPI propertieis n case of Outlook/Exchange) that
cannot
be
be
represented by the MIME envelope. It also may include
attachments.
Just out of curiosiry, why exactly are you doing this? Most
people
would
do
theopposite - parse winmail.dat and extract the regular
attachments.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"Rodrigo Mendes" <Rodrigo Mendes@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote
in
message
news:CB2B3A45-9A62-4A4E-9641-0485EF231A3D@xxxxxxxxxxxxxxxx
Hi,

I need to create a COM using MAPI to be loaded in the IIS SMTP
server
that
reads the incoming email, verifies if there is an attachment
and
if
there
is,
verifies if it is a .wav file. If it is, convert it to the TNEF
format
(a
winmail.dat file), replace the old file in the attachment by
this
new
file
(winmail,dat) and send the e-mail to the original recipient.

To do that, I'm already able to get the e-mail and send it to a
file,
using
the IMailTransportSubmission.OnMessageSubmission and the
IMailMsgProperties::CopyContentToFileEx methods.

But what I think I really need to do is to copy the e-mail to a
stream
(using the IMailMsgProperties::CopyContentToStream method).
After that, I need to store this stream in the IStorage, using
the
HrIStorageFromStream function.
Once this IStorage object is created, I can manipulate the
attachment
using
the IMessage interface (using GetAttachment, AddAttachment,
...)
and
the
OpenTnefStream function and so on.

The problem is that, to start, my mailmsg.h does not have the
CopyContentToStream.

Do you have any suggestion to solve this problem ?

The bottom line here is that I need to get the mail that I have
available
with the MailMsg interface and handle it using the IMessage
inteface.
Is
this the right approach to get this done ?

Thanks in advance.


.



Relevant Pages

  • Re: How to replace an attachment from a file.wav to a winmail.dat
    ... we created one stream object with the contents of the file using the ... and we created the new tnef stream using the OpenTnefStreamEx ... Extended MAPI knows nothing about MIME. ... OutlookSpy - Outlook, CDO ...
    (microsoft.public.win32.programmer.messaging)
  • Re: Istorage unicode problem
    ... not have that stream but still exposed thee PR_STORE_SUPPORT_MASK property. ... OutlookSpy - Outlook, CDO ... and MAPI Developer Tool ... This property is getting set in unicode MSG files by ...
    (microsoft.public.win32.programmer.messaging)
  • Re: What is next step to extracting PST contact items
    ... IMO mode doesn't really support Extended MAPI. ... We cut IMO mode in Outlook 2002. ... and MAPI Developer Tool ... An unexpected error has occurred. ...
    (microsoft.public.win32.programmer.messaging)
  • Re: SaveChanges problem
    ... Currently we have not found any known issue regarding using OOM and MAPI ... OutlookSpy - Outlook, CDO ... been able to duplicate it normally, but I can when using Outlook Spy ...
    (microsoft.public.win32.programmer.messaging)
  • Re: SaveChanges problem
    ... Currently we have not found any known issue regarding using OOM and MAPI ... OutlookSpy - Outlook, CDO ... been able to duplicate it normally, but I can when using Outlook Spy ...
    (microsoft.public.win32.programmer.messaging)