FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Automated Outlook e-mail and sending plain text
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Automated Outlook e-mail and sending plain text
Posted: Tue Oct 19, 2021 06:28 PM
To All

I have automated a WorkGroup application that generates an Outlook 365 ( client ) e-mail ... the code is simple enough and it works quite well .. however I am having problems with some users that can not see the Body ( cBody ) of the message .. which I code as plain text ...

Here is the code:

Code (fw): Select all Collapse
         cBody    := "Dear Employee: "+alltrim( cEMployee )+";"+chr(10)
         cBody    += "From "+cMan1+" "+chr(10)
         cBody    += "  "+chr(10)
         cBody    += "  "+chr(10)
         cBody    += "A Travel /  Train request has been reviewed and Approved by "+alltrim(cMan1)+"."+chr(10)
         cBody    += "The Final Disposition : "+cCloseType+" Dated "+dtoc(dFinalDt)+"."+chr(10)
         cBody    += "  "+chr(10)
         cBody    += "Please see the Link instructions Provided below. ** "+chr(10)
         cBody    += " "+chr(10)
         cBody    += " "+chr(10)
         cBody    += "Summary of Request:"+chr(10)
         cBody    += "  "+chr(10)
         cBody    += "   *  Employee Name: "+alltrim( cEmployee )+chr(10)
         cBody    += "   *  Vendor Sponsor: "+alltrim( cSponsor )+chr(10)
         cBody    += "   *  Conference/Event: "+alltrim( cEvent )+chr(10)
         cBody    += "   *  Location: "+alltrim( cLocation )+chr(10)
         cBody    += "   *  Start Date:  "+dtoc( dLeave )+chr(10)
         cBody    += "   *  End Date:    "+dtoc( dReturn )+chr(10)
         cBody    += "   *  Estimated Cost:  $"+Transform(nTotalExp,"999,999.99" )+chr(10)

         If cExam = "Y" .and. ( cQuality = "N" .and. cMgmt = "N" .and. cTech = "N" .and. cDev = "N" .and. cConf = "N" )
            cBody    += "   *  Is this Request for Examination Travel ONLY? : Yes"+chr(10)
         Else
            cBody    += "   *  Is this Request for Examination Travel ONLY? : No"+chr(10)
         Endif

         cBody    += "   *  Is This Associated with a Previously approved Designation? : "+cPrevAppr+chr(10)
         cBody    += "  "+chr(10)
         cBody    += "  "+chr(10)
         cBody    += alltrim(cAppUrl)+" /"+alltrim( cPersno )+chr(10)
         cBody    += "  "+chr(10)
         cBody    += "**   To run .. hold down the Windows key + R ...  "+chr(10)
         cBody    += "Cut and Paste the entire link above into the open RUN line and hit"+chr(10)
         cBody    += "OK to start the Program"+chr(10)
         cBody    += "  "+chr(10)
         cBody    += "  "+chr(10)
         cBody    += "  "+chr(10)
         cBody    += "  "+chr(10)
         cBody    += "  "+chr(10)
         cBody    += "Note .. This is an automated e-mail sent from the Leave / Travel Program"+chr(10)
         cBody    += "  "+chr(10)


Not rocket science so far ....

Here is my Outlook "silent" e-mail generation ....

Code (fw): Select all Collapse
Try
   oOutLook  := TOleAuto():New("Outlook.Application")
Catch
    Saying := "For some Odd reason The Outlook e-mail CLient failed to Initialize"
    Msginfo( Saying )
    Return(.f.)
End Try

oMailItem := oOutLook:Invoke("CreateItem", 0)

oMailitem:to := cTo
oMailitem:CC := cCC
oMailItem:Subject := cSubject
oMailItem:Body := cBody               // just plain text

Try
   oMailItem:display(.F.)
Catch
End Try

Try
   oMailItem:Invoke("Send")
Catch
End Try


The e-mail is generated and sent to the recipient .. however, in a couple of cases .. cBody is not being resolved in the e-mail .. just a big white space .. By default all the OUtlook settings are set to allow HTML .... even the ones that DO recieve the message where cBody is just plain text ...

I am just curious if chr(10) at the end of the text may be causing any problems .. however, only a select few recipients have any problem at all seeing the body of the message ... I am just curious if changing cBody to HTML may be a ( positive ) common denominator ...

I would be grateful if any HTML Gurus could look at cBody and re-code it for HTML ??? however, I don't know if HTML vs plain text will resolve anything .. I am OPEN to any comments and suggestions ...

Thanks
Rick Lipkin
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Automated Outlook e-mail and sending plain text
Posted: Tue Oct 19, 2021 06:56 PM

Dear Rick,

oMailItem:HtmlBody = cHTML

Use "<br>" instead of Chr( 10 )

and remember to use the typical HTML structure:

<html>
<head>
</head>
<body>
Your text goes here
</body>
</html>

You can use tables, colors, etc.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: Automated Outlook e-mail and sending plain text
Posted: Tue Oct 19, 2021 07:19 PM

Antonio

Thank you .. would you mind giving me a quick example of the plain text conversion ??

Rick Lipkin

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Automated Outlook e-mail and sending plain text
Posted: Wed Oct 20, 2021 10:11 AM
Rick,

not sure if this is what you mean
Code (fw): Select all Collapse
local cHTML

TEXT INTO cHTML
   <html>
   <head>
   </head>
   <body>
   Your text goes here
   </body>
   </html>
ENDTEXT

oMailItem:HtmlBody = cHTML
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion