How to create a new plain text message? 
Author Message
 How to create a new plain text message?

I am rather baffled at how to create a plain text message using the Outlook
object model regardless of the user's default settings.  When I use the Body
property it usually gives a Rich Text message.

If I assign it to the HTMLBody property (using <PRE> tags) I get an HTML
formatted message.

By displaying the message the user can then change the format to plain text
using the menu but how do I do this programatically?

Any help would be greatly appreciated.
Many thanks,
Blythe



Fri, 21 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
Create the body of the message using CDO. That will produce a plain
text message.

Sub cdoPlainText()
  Dim oOL As Outlook.Application
  Dim oSession As MAPI.session
  Dim oMsg As MAPI.Message
  Dim oMail As Outlook.MailItem
  Dim sEntry As String

  Set oOL = CreateObject("Outlook.Application")
  Set oMail = oOL.CreateItem(olMailItem)
  oMail.To = "John Doe"
  oMail.Subject = "Test Plain Text Message"
  oMail.Save 'Have to save it to get an EntryID

  'We need the EntryID of the item to locate it with CDO
  sEntry = oMail.EntryID
  oMail.Close olDiscard

  'Establish a CDO (MAPI) Session object and logon to it
  Set oSession = CreateObject("MAPI.Session")
  oSession.Logon , , False, False

  'Locate the message with the EntryID using CDO
  Set oMsg = oSession.GetMessage(sEntry)

  oMsg.Text = "This is not RTF, even though the Body was touched"
  oMsg.Update 'Leave the message in Drafts

  Set oSession = Nothing
  Set oMsg = Nothing
  Set oOL = Nothing
  Set oMail = Nothing
End Sub

--
Ken Slovak
[MVP - Outlook]
Co-author of "Programming Microsoft Outlook 2000"
Chapters 8-13, Appendices
Sams, Sept. 1999


Quote:
> I am rather baffled at how to create a plain text message using the
Outlook
> object model regardless of the user's default settings.  When I use
the Body
> property it usually gives a Rich Text message.

> If I assign it to the HTMLBody property (using <PRE> tags) I get an
HTML
> formatted message.

> By displaying the message the user can then change the format to
plain text
> using the menu but how do I do this programatically?

> Any help would be greatly appreciated.
> Many thanks,
> Blythe



Fri, 21 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
Cool trick, Ken!!  Thanks for posting this.  I had no idea CDO could be used
to do this.

--
Regards,
Chris Burnham (MVP-Outlook)
Co-author, Professional Outlook 2000 Programming, from Wrox Press
http://www.amazon.com/exec/obidos/ASIN/1861003315/qid%3D946430486/sr%...
04-7532560-6100408
http://shop.barnesandnoble.com/booksearch/isbnInquiry.asp?userid=65X2...
mscssid=Q9DSGMJGPVSH2NJH0017QJ1R0HMB18UC&srefer=&salesurl=Rwww.bn.com/&isbn=
1861003315

Please reply to the newsgroups so that others can benefit from the
discussion.  Also note that I do not send replies to newsgroup postings or
other questions by e-mail  I volunteer my time in the groups. Thanks for
understanding and supporting the forum.
_______________________________


Create the body of the message using CDO. That will produce a plain
text message.

Sub cdoPlainText()
  Dim oOL As Outlook.Application
  Dim oSession As MAPI.session
  Dim oMsg As MAPI.Message
  Dim oMail As Outlook.MailItem
  Dim sEntry As String

  Set oOL = CreateObject("Outlook.Application")
  Set oMail = oOL.CreateItem(olMailItem)
  oMail.To = "John Doe"
  oMail.Subject = "Test Plain Text Message"
  oMail.Save 'Have to save it to get an EntryID

  'We need the EntryID of the item to locate it with CDO
  sEntry = oMail.EntryID
  oMail.Close olDiscard

  'Establish a CDO (MAPI) Session object and logon to it
  Set oSession = CreateObject("MAPI.Session")
  oSession.Logon , , False, False

  'Locate the message with the EntryID using CDO
  Set oMsg = oSession.GetMessage(sEntry)

  oMsg.Text = "This is not RTF, even though the Body was touched"
  oMsg.Update 'Leave the message in Drafts

  Set oSession = Nothing
  Set oMsg = Nothing
  Set oOL = Nothing
  Set oMail = Nothing
End Sub

--
Ken Slovak
[MVP - Outlook]
Co-author of "Programming Microsoft Outlook 2000"
Chapters 8-13, Appendices
Sams, Sept. 1999


Quote:
> I am rather baffled at how to create a plain text message using the
Outlook
> object model regardless of the user's default settings.  When I use
the Body
> property it usually gives a Rich Text message.

> If I assign it to the HTMLBody property (using <PRE> tags) I get an
HTML
> formatted message.

> By displaying the message the user can then change the format to
plain text
> using the menu but how do I do this programatically?

> Any help would be greatly appreciated.
> Many thanks,
> Blythe



Sat, 22 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
Thank YOU!  That worked well.
I'm sure this will be useful to a few of us...
Regards,
Blythe



Quote:
> Cool trick, Ken!!  Thanks for posting this.  I had no idea CDO could be
used
> to do this.

> --
> Regards,
> Chris Burnham (MVP-Outlook)
> Co-author, Professional Outlook 2000 Programming, from Wrox Press

http://www.amazon.com/exec/obidos/ASIN/1861003315/qid%3D946430486/sr%...
Quote:
> 04-7532560-6100408

http://shop.barnesandnoble.com/booksearch/isbnInquiry.asp?userid=65X2...
mscssid=Q9DSGMJGPVSH2NJH0017QJ1R0HMB18UC&srefer=&salesurl=Rwww.bn.com/&isbn=
Quote:
> 1861003315

> Please reply to the newsgroups so that others can benefit from the
> discussion.  Also note that I do not send replies to newsgroup postings or
> other questions by e-mail  I volunteer my time in the groups. Thanks for
> understanding and supporting the forum.
> _______________________________

message

> Create the body of the message using CDO. That will produce a plain
> text message.

> Sub cdoPlainText()
>   Dim oOL As Outlook.Application
>   Dim oSession As MAPI.session
>   Dim oMsg As MAPI.Message
>   Dim oMail As Outlook.MailItem
>   Dim sEntry As String

>   Set oOL = CreateObject("Outlook.Application")
>   Set oMail = oOL.CreateItem(olMailItem)
>   oMail.To = "John Doe"
>   oMail.Subject = "Test Plain Text Message"
>   oMail.Save 'Have to save it to get an EntryID

>   'We need the EntryID of the item to locate it with CDO
>   sEntry = oMail.EntryID
>   oMail.Close olDiscard

>   'Establish a CDO (MAPI) Session object and logon to it
>   Set oSession = CreateObject("MAPI.Session")
>   oSession.Logon , , False, False

>   'Locate the message with the EntryID using CDO
>   Set oMsg = oSession.GetMessage(sEntry)

>   oMsg.Text = "This is not RTF, even though the Body was touched"
>   oMsg.Update 'Leave the message in Drafts

>   Set oSession = Nothing
>   Set oMsg = Nothing
>   Set oOL = Nothing
>   Set oMail = Nothing
> End Sub

> --
> Ken Slovak
> [MVP - Outlook]
> Co-author of "Programming Microsoft Outlook 2000"
> Chapters 8-13, Appendices
> Sams, Sept. 1999



> > I am rather baffled at how to create a plain text message using the
> Outlook
> > object model regardless of the user's default settings.  When I use
> the Body
> > property it usually gives a Rich Text message.

> > If I assign it to the HTMLBody property (using <PRE> tags) I get an
> HTML
> > formatted message.

> > By displaying the message the user can then change the format to
> plain text
> > using the menu but how do I do this programatically?

> > Any help would be greatly appreciated.
> > Many thanks,
> > Blythe



Sat, 22 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
Thanks. Read my chapters of our book <eg>, there are some other CDO
tricks in there too :)

--
Ken Slovak
[MVP - Outlook]
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
Appendices, Sams



Quote:
> Cool trick, Ken!!  Thanks for posting this.  I had no idea CDO could
be used
> to do this.

> --
> Regards,
> Chris Burnham (MVP-Outlook)
> Co-author, Professional Outlook 2000 Programming, from Wrox Press



Sat, 22 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
Thank you for the very good Sub.

It's impossible to make a plain-text msg and to store it in the outbox?
It's the only solution to save it interim in the drafts folder?

TIA
cu zz



Quote:
> Create the body of the message using CDO. That will produce a plain
> text message.

> Sub cdoPlainText()
>   Dim oOL As Outlook.Application
>   Dim oSession As MAPI.session

    :
    :
    :
Quote:
>   Set oMail = Nothing
> End Sub

> --
> Ken Slovak
> [MVP - Outlook]
> Co-author of "Programming Microsoft Outlook 2000"
> Chapters 8-13, Appendices
> Sams, Sept. 1999



Sun, 23 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
If you want to send the item then you can from CDO. You can use the
Send method. Just add oMsg.Send. That will place it in the Outbox
ready for the next mail pass.

--
Ken Slovak
[MVP - Outlook]
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
Appendices, Sams


Quote:
> Thank you for the very good Sub.

> It's impossible to make a plain-text msg and to store it in the
outbox?
> It's the only solution to save it interim in the drafts folder?

> TIA
> cu zz



Sun, 23 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?


Quote:
> If you want to send the item then you can from CDO. You can use the
> Send method. Just add oMsg.Send. That will place it in the Outbox
> ready for the next mail pass.

Thank you for the hint.

But are you shure it's works?
In which line do you add Send?

Quote:

> --
> Ken Slovak
> [MVP - Outlook]
> Lead Author, Professional Outlook 2000 Programming, Wrox Press
> Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
> Appendices, Sams

cu zz


Mon, 24 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
It's worked for me in both C/W and IMO modes in Outlook 2000. Add the
oMsg.Send line after the oMsg.Update line.

--
Ken Slovak
[MVP - Outlook]
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
Appendices, Sams


Quote:

im

> > If you want to send the item then you can from CDO. You can use
the
> > Send method. Just add oMsg.Send. That will place it in the Outbox
> > ready for the next mail pass.

> Thank you for the hint.

> But are you shure it's works?
> In which line do you add Send?



Mon, 24 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
Boy, this is a great thread. I've been racking my brains with that
(bleep)ing object model forever trying to figure out how to do that. I have
an Access 97 application that copies a small recordset from the database and
embeds the text of it in an e-mail message in a table format. But the rich
text formatting always messes up my table; plain text works great. I have to
put the recordset directly in the message to absolutely minimize field
technician download time.

I'm not an outlook guru, but could somone please tell me if the technique of
this thread will work in Outlook 98?

Thanks,

Wayne Wolfe


Quote:
> I am rather baffled at how to create a plain text message using the
Outlook
> object model regardless of the user's default settings.  When I use the
Body
> property it usually gives a Rich Text message.

> If I assign it to the HTMLBody property (using <PRE> tags) I get an HTML
> formatted message.

> By displaying the message the user can then change the format to plain
text
> using the menu but how do I do this programatically?

> Any help would be greatly appreciated.
> Many thanks,
> Blythe



Tue, 25 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
Yes, it should work fine in Outlook 98. In fact, Outlook 98 installs
CDO automatically, unlike Outlook 2000, so you don't even have to
worry that the users might not have CDO installed.

--
Ken Slovak
[MVP - Outlook]
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
Appendices, Sams


Quote:
> Boy, this is a great thread. I've been racking my brains with that
> (bleep)ing object model forever trying to figure out how to do that.
I have
> an Access 97 application that copies a small recordset from the
database and
> embeds the text of it in an e-mail message in a table format. But
the rich
> text formatting always messes up my table; plain text works great. I
have to
> put the recordset directly in the message to absolutely minimize
field
> technician download time.

> I'm not an outlook guru, but could somone please tell me if the
technique of
> this thread will work in Outlook 98?

> Thanks,

> Wayne Wolfe



Tue, 25 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
And there is not any way to just change the message font through the object
model is there? Courier is the Plain Text font, and if I changed the font to
that I'd have all I needed for what I do.



Quote:
> Yes, it should work fine in Outlook 98. In fact, Outlook 98 installs
> CDO automatically, unlike Outlook 2000, so you don't even have to
> worry that the users might not have CDO installed.

> --
> Ken Slovak
> [MVP - Outlook]
> Lead Author, Professional Outlook 2000 Programming, Wrox Press
> Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
> Appendices, Sams



> > Boy, this is a great thread. I've been racking my brains with that
> > (bleep)ing object model forever trying to figure out how to do that.
> I have
> > an Access 97 application that copies a small recordset from the
> database and
> > embeds the text of it in an e-mail message in a table format. But
> the rich
> > text formatting always messes up my table; plain text works great. I
> have to
> > put the recordset directly in the message to absolutely minimize
> field
> > technician download time.

> > I'm not an outlook guru, but could somone please tell me if the
> technique of
> > this thread will work in Outlook 98?

> > Thanks,

> > Wayne Wolfe



Tue, 25 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
No, the message font is also not exposed in the object model. If you
create a plain text message using the CDO code it will just use
whatever is set as the default plain text message font.

--
Ken Slovak
[MVP - Outlook]
Lead Author, Professional Outlook 2000 Programming, Wrox Press
Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
Appendices, Sams


Quote:
> And there is not any way to just change the message font through the
object
> model is there? Courier is the Plain Text font, and if I changed the
font to
> that I'd have all I needed for what I do.



Fri, 28 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
Hi Zeno,

This did not work for me, so I used a workaround. Move the line "Dim sEntry
As String" outside the procedure, i.e. so that it is now global in scope and
add this procedure:-

Public Sub SendSavedMessage()
'--------------------------------------------------
' SendSavedMessage
' This should be called after SendPlainMessage
' which will initialize the global sEntry variable
'--------------------------------------------------
Dim oNS As Outlook.NameSpace
Set oNS = Application.GetNamespace("MAPI")
Set oMail = oNS.GetItemFromID(sEntry)
oMail.Send
Set oNS = Nothing

End Sub

I have a function called SendPlainMessage which I pass the parameters, To,
Subject, etc and if it returns successfully then I call SendSavedMessage to
move it from the Drafts folder to the Outbox. There is a whole thread on
this called "Accessing the Menus". Cheers
Gary

Quote:
> > If you want to send the item then you can from CDO. You can use the
> > Send method. Just add oMsg.Send. That will place it in the Outbox
> > ready for the next mail pass.

> Thank you for the hint.

> But are you shure it's works?
> In which line do you add Send?



Sat, 29 Jun 2002 03:00:00 GMT  
 How to create a new plain text message?
Since you're using Outlook 98, another possibility is to use the HTMLBody
property to create an HTML-format message with exactly the fonts/layout you
want. It takes some minimal knowledge of HTML tags, but you can easily get
that by creating a sample in any WYSIWYG HTML editor, then looking at the
source code.
--
Sue Mosher
Author of
  "Teach Yourself Microsoft Outlook 2000 Programming in 24 Hours"
  "Microsoft Outlook 2000 E-mail and Fax Guide"

Outlook and Exchange solutions at http://www.slipstick.com


Quote:
> And there is not any way to just change the message font through the
object
> model is there? Courier is the Plain Text font, and if I changed the font
to
> that I'd have all I needed for what I do.



> > Yes, it should work fine in Outlook 98. In fact, Outlook 98 installs
> > CDO automatically, unlike Outlook 2000, so you don't even have to
> > worry that the users might not have CDO installed.

> > --
> > Ken Slovak
> > [MVP - Outlook]
> > Lead Author, Professional Outlook 2000 Programming, Wrox Press
> > Co-author of "Programming Microsoft Outlook 2000", Chapters 8-13,
> > Appendices, Sams



> > > Boy, this is a great thread. I've been racking my brains with that
> > > (bleep)ing object model forever trying to figure out how to do that.
> > I have
> > > an Access 97 application that copies a small recordset from the
> > database and
> > > embeds the text of it in an e-mail message in a table format. But
> > the rich
> > > text formatting always messes up my table; plain text works great. I
> > have to
> > > put the recordset directly in the message to absolutely minimize
> > field
> > > technician download time.

> > > I'm not an outlook guru, but could somone please tell me if the
> > technique of
> > > this thread will work in Outlook 98?

> > > Thanks,

> > > Wayne Wolfe



Tue, 02 Jul 2002 03:00:00 GMT  
 
 [ 15 post ] 

 Relevant Pages 

1. setting a new mail-message to plain text via CDO

2. Creating e-mail is always Rich Text NOT Plain Text

3. Creating a new text or HTML message and using Word as an editor

4. create new contact from email message text

5. OL2002 ignoring line wrap setting for plain text email messages

6. Set message format to plain text

7. How to detect if a new mail is of plain text or html

8. Creating Plain Text E-Mails with Outlook 2000

9. creating a text box errors message for empty text box

10. Creating word Macro to copy text and create new files from existing one

11. Converting formatted text to plain text

12. Mapping plain text to rich text?

 

 
Powered by phpBB® Forum Software