Saving HTML attachments

S

Shay Levi

Dmitry,

I would like to thank you for your help. RDOMail did the trick.

Thanks!!!

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic


It is an embedded message attachment that happens to have HTML body.
Check the the Attachment.Type property before saving attachments. If
it is
olEmbeddeditem (5), you have an embedded message and you wiull have an
MSG
file when you call SaveAsFile. You can try to import it back to
Outlook
using Application.CreateItemFromTemplate, but it will skip any sender
related properties.
<plug> Redemption exposes RDOAttachment.EmbeddedMsg property (returns
RDOMail object) which you can use to call RDOMail.SaveAs ..., olHTML
</plug>
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Sorry, I may have used the wrong "outlook/attachment" terms for that
attachment. I don't know the exact definition (envelop???).
Anyway, see the attached jpg, It shows how I see it in Outlook 2007.
When
I double click it
it opens inside outlook's message windows and I can see the HTML page
the
message contains. When I say HTML, it's
like any HTML webpage.
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
That can only mean that the attachment is an embedded message, not
an
HTML
attachment.
What makes you think that you have an HTML attachment?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
file.Attachments.Item(1).SaveAsFile("message.txt");

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
How *exactly* do you save the messages?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Thanks Dmitry, any suggestion on how to turn it into text file?

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
That looks like an MSG file (which is an OLE storage file).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Thanks Ken,

When I double click the attachment it opens inside outlook.
here's a sample text from the saved msg file:

(...)
???????????????????????????????????????????????????????????????
??
??
??
??????????????????????????R
o o t E n t r y
? ? ????????
p[?~?G??
?? _ _ p r o p e r t i e s _ v e r s i o n 1 . 0
0
??? ? ???? J P?
_ _ n a m e i d _ v e r s i o n 1 . 0
(
??????????/ ???}?G???_?}?G?? _ _ s u b s
t g 1 . 0 _ 0 E 0 4 0 0 1 F * ??????#
????
?
. ? ????????????? ?
? I ????( ? ? ? ? ? ¶ § ? ? ? ? ?
?
?
?
? ? ! " # $ % & ' ????A * + ,
- . / 0 1 2 3 4 5 6 7 8 9 : ; <
=
?
@ ????B C D E F G H M J K L ????N O
P
???????????????????????????????????????????????????????????????
??
??
??
???????????????????????????????????????????????????????????????
??
(...)
One thing I did not mention, I could save the HTML attachents
to
readable
text files when my Exchange server was v2003, I think
the problem started when I switched to Exchange 2007.
Is there any configuration I can set in Outlook to resolve this
(Mail
Format, Mail Setup Tabs)?
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
You can't open an attachment programmatically, so that option
isn't available for code. It's possible that the text file
contains text in Unicode, where every other character would be
0x00 for Western character sets. You'll have to figure out how
the text file is encoded and how to decode that into readable
text or an alternative is to see what program opens the file
when you open it in the UI and then automate that program to
open the attachment file saved to the file system.

Thanks Ken,

I already tried it. The text file contains unreadable
characters(binary
encoding???).
Even if I manually (GUI) save the attachment to disk (.msg or
.txt)
the
text file is still unreadable.
The only solution I found is to view the attachment in
Outlook
and
then
save the source to disk.
The problem is I get, at list, 25 emails per a day and
manually
proccesing
each one is painfull!
The only solution I found is to double click it (don't use
the
preview
option) and from file menu save
the file as HTML.
Can this steps be automated with a Macro? If so, can one
suggest
one.
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog:
http://blogs.microsoft.co.il/blogs/scriptfanatic
 
D

Dmitry Streblechenko

olEmbeddeditem is just onbe of the possible attachment types. Others are
olByValue (1), olByReference(4), olOLE (6).
CreateItemFromTemplate simply lets you create a new message from an MSG
file, this way you will have access to the MailItem.SaveAs method.
The downside is that you need to create an intermediate MSG file and then
import it back to begin with rather than work with the original embedded
message attachment (that is what Redemption lets you do).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Shay Levi said:
True... all attachments type are olEmbeddeditem items. Can you elaborate a
bit
on Application.CreateItemFromTemplate? I'm not familiar with it and not
sure how can
use it to turn the embedded attachment into readable text, I don't mind
losing
the sender or other properties as long as I can export its content to a
readable text file.

BTW, prior to Exchange 2007 I had no problems.

I'm also going to take a closer look on RDOMail (which is already opened
in IE :).


Thanks!

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic


It is an embedded message attachment that happens to have HTML body.
Check the the Attachment.Type property before saving attachments. If
it is
olEmbeddeditem (5), you have an embedded message and you wiull have an
MSG
file when you call SaveAsFile. You can try to import it back to
Outlook
using Application.CreateItemFromTemplate, but it will skip any sender
related properties.
<plug> Redemption exposes RDOAttachment.EmbeddedMsg property (returns
RDOMail object) which you can use to call RDOMail.SaveAs ..., olHTML
</plug>
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Sorry, I may have used the wrong "outlook/attachment" terms for that
attachment. I don't know the exact definition (envelop???).
Anyway, see the attached jpg, It shows how I see it in Outlook 2007.
When
I double click it
it opens inside outlook's message windows and I can see the HTML page
the
message contains. When I say HTML, it's
like any HTML webpage.
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
That can only mean that the attachment is an embedded message, not
an
HTML
attachment.
What makes you think that you have an HTML attachment?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
file.Attachments.Item(1).SaveAsFile("message.txt");

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
How *exactly* do you save the messages?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Thanks Dmitry, any suggestion on how to turn it into text file?

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
That looks like an MSG file (which is an OLE storage file).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Thanks Ken,

When I double click the attachment it opens inside outlook.
here's a sample text from the saved msg file:

(...)
???????????????????????????????????????????????????????????????
??
??
??
??????????????????????????R
o o t E n t r y
? ? ????????
p[?~?G??
?? _ _ p r o p e r t i e s _ v e r s i o n 1 . 0
0
??? ? ???? J P?
_ _ n a m e i d _ v e r s i o n 1 . 0
(
??????????/ ???}?G???_?}?G?? _ _ s u b s
t g 1 . 0 _ 0 E 0 4 0 0 1 F * ??????#
????
?
. ? ????????????? ?
? I ????( ? ? ? ? ? ¶ § ? ? ? ? ?
?
?
?
? ? ! " # $ % & ' ????A * + ,
- . / 0 1 2 3 4 5 6 7 8 9 : ; <
=
?
@ ????B C D E F G H M J K L ????N O
P
???????????????????????????????????????????????????????????????
??
??
??
???????????????????????????????????????????????????????????????
??
(...)
One thing I did not mention, I could save the HTML attachents
to
readable
text files when my Exchange server was v2003, I think
the problem started when I switched to Exchange 2007.
Is there any configuration I can set in Outlook to resolve this
(Mail
Format, Mail Setup Tabs)?
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
You can't open an attachment programmatically, so that option
isn't available for code. It's possible that the text file
contains text in Unicode, where every other character would be
0x00 for Western character sets. You'll have to figure out how
the text file is encoded and how to decode that into readable
text or an alternative is to see what program opens the file
when you open it in the UI and then automate that program to
open the attachment file saved to the file system.

Thanks Ken,

I already tried it. The text file contains unreadable
characters(binary
encoding???).
Even if I manually (GUI) save the attachment to disk (.msg or
.txt)
the
text file is still unreadable.
The only solution I found is to view the attachment in
Outlook
and
then
save the source to disk.
The problem is I get, at list, 25 emails per a day and
manually
proccesing
each one is painfull!
The only solution I found is to double click it (don't use
the
preview
option) and from file menu save
the file as HTML.
Can this steps be automated with a Macro? If so, can one
suggest
one.
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog:
http://blogs.microsoft.co.il/blogs/scriptfanatic
 
D

Dmitry Streblechenko

Cool!

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Shay Levi said:
Dmitry,

I would like to thank you for your help. RDOMail did the trick.

Thanks!!!

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic


It is an embedded message attachment that happens to have HTML body.
Check the the Attachment.Type property before saving attachments. If
it is
olEmbeddeditem (5), you have an embedded message and you wiull have an
MSG
file when you call SaveAsFile. You can try to import it back to
Outlook
using Application.CreateItemFromTemplate, but it will skip any sender
related properties.
<plug> Redemption exposes RDOAttachment.EmbeddedMsg property (returns
RDOMail object) which you can use to call RDOMail.SaveAs ..., olHTML
</plug>
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Sorry, I may have used the wrong "outlook/attachment" terms for that
attachment. I don't know the exact definition (envelop???).
Anyway, see the attached jpg, It shows how I see it in Outlook 2007.
When
I double click it
it opens inside outlook's message windows and I can see the HTML page
the
message contains. When I say HTML, it's
like any HTML webpage.
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
That can only mean that the attachment is an embedded message, not
an
HTML
attachment.
What makes you think that you have an HTML attachment?
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
file.Attachments.Item(1).SaveAsFile("message.txt");

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
How *exactly* do you save the messages?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Thanks Dmitry, any suggestion on how to turn it into text file?

-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
That looks like an MSG file (which is an OLE storage file).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
Thanks Ken,

When I double click the attachment it opens inside outlook.
here's a sample text from the saved msg file:

(...)
???????????????????????????????????????????????????????????????
??
??
??
??????????????????????????R
o o t E n t r y
? ? ????????
p[?~?G??
?? _ _ p r o p e r t i e s _ v e r s i o n 1 . 0
0
??? ? ???? J P?
_ _ n a m e i d _ v e r s i o n 1 . 0
(
??????????/ ???}?G???_?}?G?? _ _ s u b s
t g 1 . 0 _ 0 E 0 4 0 0 1 F * ??????#
????
?
. ? ????????????? ?
? I ????( ? ? ? ? ? ¶ § ? ? ? ? ?
?
?
?
? ? ! " # $ % & ' ????A * + ,
- . / 0 1 2 3 4 5 6 7 8 9 : ; <
=
?
@ ????B C D E F G H M J K L ????N O
P
???????????????????????????????????????????????????????????????
??
??
??
???????????????????????????????????????????????????????????????
??
(...)
One thing I did not mention, I could save the HTML attachents
to
readable
text files when my Exchange server was v2003, I think
the problem started when I switched to Exchange 2007.
Is there any configuration I can set in Outlook to resolve this
(Mail
Format, Mail Setup Tabs)?
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
You can't open an attachment programmatically, so that option
isn't available for code. It's possible that the text file
contains text in Unicode, where every other character would be
0x00 for Western character sets. You'll have to figure out how
the text file is encoded and how to decode that into readable
text or an alternative is to see what program opens the file
when you open it in the UI and then automate that program to
open the attachment file saved to the file system.

Thanks Ken,

I already tried it. The text file contains unreadable
characters(binary
encoding???).
Even if I manually (GUI) save the attachment to disk (.msg or
.txt)
the
text file is still unreadable.
The only solution I found is to view the attachment in
Outlook
and
then
save the source to disk.
The problem is I get, at list, 25 emails per a day and
manually
proccesing
each one is painfull!
The only solution I found is to double click it (don't use
the
preview
option) and from file menu save
the file as HTML.
Can this steps be automated with a Macro? If so, can one
suggest
one.
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog:
http://blogs.microsoft.co.il/blogs/scriptfanatic
 

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

Top