MailItem SaveAs method

  • Thread starter Thread starter Bingo
  • Start date Start date
B

Bingo

Using SaveAs method, I can save an email to disk. But in
the saved file, Outlook automatically adds From, To, CC
and Subject on the top of the mesasge body. Is it
possible to just save the email body? Thanks.
 
Hi Bingo,

you can use this function to write the body in a file:

Private Sub WriteFile(sPath As String, _
sText As String, _
ByVal bAppend As Boolean _
)
On Error GoTo AUSGANG
Dim fn As Long

fn = FreeFile

Select Case bAppend
Case False
Open sPath For Output As #fn
Case Else
Open sPath For Append As #fn
End Select

Print #fn, sText

AUSGANG:
If fn Then
Close #fn
End If

If Err.Number Then Err.Raise Err.Number Or &H800A0000, _
Err.Source, Err.Description, Err.HelpFile, Err.HelpContext
End Sub

Also, not my favorite but easy to use: the FileSystemObject in Microsoft
Scripting Runtime (scrrun.dll)
 
Michael,

The performance is terriblely slow for a message with a
picture in it.

Anything can be done in Outlook? Thanks.
 
You could use SaveAs to save the file with your desired format, then use
methods appropriate for that file format to strip the header information
out.
 
Sue,

So I guess from your reply that there's no way in Outlook
to get rid of the header information?

I tried both text file line by line reading as Michael
recommended and RichText Control line by line reading,
both are very slow for a mail with an image. Even I know
the header is always at the beginning of each saved file,
but the two above solutions have to read all file line by
line. Any recommendations for a better solution?
Thanks.
 
Correct. You've already had my recommendation for an alternative. But I just
thought of a sneaky one that might work if WordMail is your editor. Save the
message as an .msg file. Open a copy of it with
Namespace.CreateItemFromTemplate. Then use the Inspector.WordDocument's Save
method to save the body of the newly created message.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Hi Bingo,
I tried both text file line by line reading as Michael
recommended and RichText Control line by line reading,

I´ve never said, that you must read something line by line. Regarding to
your OP the function writes the complete body at once to a file.
 
Michael,

I'm sorry if I mis-understood your recommendation.

I need to find a way to save a RTF formatted message without the extra
heading section in it. But I cannot figure out how to utilize the function
your recommendated. How do I get the sText with all the formatting tags as
well as all the embedded OLE objects if any before I save it to a file?

Thanks.
 
Hi Bingo,

I thought you want to save just the body.
How do I get the sText with all the formatting tags as
well as all the embedded OLE objects

For that I would go Sue´s suggested way, too. Use the OL SaveAs method
for saving all data in an *.rtf file. Then open that file, cut
unnecessary infos and save that file again.

In additon to my WriteFile method you can use this for reading the saved
file:

Public Function ReadFile(sPath As String) As String
On Error GoTo AUSGANG
Dim lFileNr As Long
Dim sText As String

lFileNr = FreeFile

Open sPath For Binary As #lFileNr
sText = Space$(LOF(lFileNr))
Get #lFileNr, , sText

AUSGANG:
If lFileNr Then
Close #lFileNr
End If

If Err.Number Then Err.Raise &H800A0000 Or Err.Number, _
Err.Source, Err.Description, Err.HelpFile, Err.HelpContext

ReadFile = sText
End Function
 
<plug>
You can use Redemption for that (url below):

set sItem = CreateObject("Redemption.SafeMailItem")
sItem.Item = YourOutlookMailItem
strRTFBody = sItem.RTFBody

Note that the current version of Redemption won't return the embedded OLE
objects in the RTFBody property (Outlook stores them separately in
attachments).

</plug>

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


Bingo said:
Michael,

I'm sorry if I mis-understood your recommendation.

I need to find a way to save a RTF formatted message without the extra
heading section in it. But I cannot figure out how to utilize the function
your recommendated. How do I get the sText with all the formatting tags as
well as all the embedded OLE objects if any before I save it to a file?

Thanks.
 
Back
Top