Announcement

Collapse
No announcement yet.

How to set Rich Text in Outlook COM email

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to set Rich Text in Outlook COM email

    Using the Outlook Dispatch interface, I have code that will produce emails with attachments either for sending or saving in the draft folder.

    What setting or property is used to set the body of the email to rich text or html? How would this be done?

    Thank you,

    Bob Mechler

  • #2
    Here is the simplest way to do it. Probably others. Boilerplate rtf code could use tags etc for each email to personalize it.

    Code:
    'How to send an email with rich text body and two attachments using PB COM
    'Initial version. Needs appropriate error checking.
    'Bob Mechler
    
    #COMPILE EXE "pbemail.exe"
    #INCLUDE"WIN32API.INC"
    #INCLUDE"oOUTLOOK.INC" 'Derived from PB COM Browswer
    FUNCTION PBMAIN
    
      DIM o_mlApplication AS OutlookApplication
      DIM o_mlNameSpace AS OutLookNameSpace
      DIM o_mlMailitem AS OutLookMailItem
      DIM vSpace AS VARIANT
      DIM vMapi AS VARIANT
      DIM vMail AS VARIANT
      DIM vItemType AS VARIANT
      DIM vSubject AS VARIANT
      DIM vBody AS VARIANT
      DIM vTo AS VARIANT
      DIM vVnt AS VARIANT
    
      SET o_mlApplication = NEW OutLookApplication IN $PROGID_OutLookApplication9
      vMapi = "mapi"
      OBJECT CALL o_mlApplication.GetNameSpace(vMapi) TO vSpace
    
      SET o_mlNameSpace = vSpace
      OBJECT CALL o_mlNameSpace.Logon
    
      OBJECT CALL o_mlApplication.CreateItem(vItemType) TO vMail
      SET o_mlMailItem = vMail
    
      vSubject = "Pb Email using Outlook"
      OBJECT LET o_mlMailItem.Subject = vSubject
    
      vBody = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\froman\fcharset0 Times New Roman;}{\f1\fswiss\fcharset0 Arial;}}"+$CRLF+ _
    "\viewkind4\uc1\pard\sb100\sa100\lang3081\f0\fs24 ""Hello world. \b This is bold\b0 , and \i this is italic\i0 .\line This is a copyright sign: \'a9""\lang1033\f1\fs20\par"+$CRLF+ _
    "}"
    
      OBJECT LET o_mlMailItem.Body = vBody
    
      vTo = "[email protected]"
      OBJECT LET o_mlMailItem.To = vTo
    
      vVnt = "c:\pdfs\COMC.PDF"
      OBJECT CALL o_mlMailItem.Attachments.Add(vVnt)
    
      vVnt = "c:\pdfs\CULAND2.PDF"
      OBJECT CALL o_mlMailItem.Attachments.Add(vVnt)
      'goes to draft folder. Use send to send it
      OBJECT CALL o_mlMailItem.save
    
       SET o_mlMailItem = NOTHING
       SET o_mlNameSpace = NOTHING
       SET o_mlApplication = NOTHING
    
      OBJECT CALL o_mlNameSpace.Logoff
    
    END FUNCTION
    Bob Mechler

    Comment

    Working...
    X