How can I distinguish the email body is plain text or html body?

E

epjames

My outlook is version 2000. I used MailItem.Body to
capture the content of the Email to the database, but I
found that the content will be changed to <html>...</html>
while it's in HTML format. How can I distinguish the
plain text or html? How to set the Email to send a HTML
format? If I paste the whole text <html>...</html> in the
Email's body and send to other people, will they see the
HTML format or just the text <html>...</html>?

Thanks in advance.
epjames
 
G

Guest

To check for HTML mails, use the MailItem.BodyFormat
formats
olFormatPlain
olFormatRichText
olFormatHTML
lFormatUnspecified (?)

to send emails in HTML use
MailItem.HTMLBody

code snippet
Select Case Item.BodyFormat
Case olFormatHTML
sBodyText = Item.HTMLBody
Case Else
'olFormatPlain, olFormatRichText, lFormatUnspecified?
sBodyText = Item.Body
End Select
 
S

Sue Mosher [MVP-Outlook]

That won't work in Outlook 2000, where you need to use Inspector.EditorType
instead.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
E

epjames

Thanks all for your help!

If I received a HTML format email, can I save the body in
text or others (e.g. image) format, then I can retrieve
the body later? It is because I write an application to
capture all information of the email such as sender name,
sender email address, any attachments and the content of
the body. All the information will be saved in the SQL
Server, then will send the email to other persons with
that information.
 
G

Guest

Thanks.

I used the GetInspector.EditorType to check the format.
However, I can't get the "HTMLBody" from the email even
the EditorType is 2. I can use the "Body" to get the
content, but the content is plain text format. Also, can
I use the string data type to store the HTML content,
because I found that they only store a little part of the
email only.
 
S

Sue Mosher [MVP-Outlook]

What happens when you try to use HTMLBody?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Nothing.

Here is my code:

Set myOlApp = Outlook.Application
Set mynamespace = myOlApp.GetNamespace("MAPI")

Set myExp = myOlApp.ActiveExplorer
Set mysel = myExp.Selection
For Each obj In mysel
If TypeName(obj) = "MailItem" Then
Select Case obj.GetInspector.EditorType
Case "1"
MsgBox obj.Body
MsgBox "1. Body"

Case "2"
MsgBox obj.HTMLBody
MsgBox "2. HTMLBody"
MsgBox obj.Body

End Select
End if
Next
 
S

Sue Mosher [MVP-Outlook]

It might be interesting to use Outlook Spy to examine such a message that
says it's HTML but has a blank body.

Alternatively, you could try saving the item as an HTML file with
MailItem.SaveAs and then use the data from that file.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
G

Guest

Thanks Sue,

The case is that I used the outlook express to send a HTML
format email to outlook, the editortype is shown 2, but
the HTMLBody is blank. I try to use your method to save
the content, but it also saved the information of From,
Send, To and Subject. Can I save the content only?

By the way, what is Outlook Spy?
 
S

Sue Mosher [MVP-Outlook]

Outlook Spy is an essential third-party tool for Outlook developers that
allows you to see the details inside items. Get it from
http://www.dimastr.com/

My guess is that the message might really be blank. Standard troubleshooting
would include sending a similar message to an account that you can access
with Outlook Express or any other mail program that allows you to see the
full raw message source.
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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