3 June 2010

Example-Database

Sandbox to test how it works.

testszenario

Don't forget to install the appropriate 4D Internet commands!

Example-Result

mailreceiveNoPicture

 

Explanation

Send a 4D Write-area as HTML-eMail

ozWR_eMailMngr expects up to 4 Parameters

  • $1 = do what (Text)
  • $2 = wr_area (Longint)
  • $3 = P_Object (Pointer, optional)
  • $4 = P_PathsArray (Pointer Array text, optional)

Example

For a single eMail just one line:

$error_L:=ozWR_eMailMngr ("eMail_Send";wr_Area;->a_ParametersContent_T;->a_AttachPaths_T)
a_AttachPaths_T is optional

a_ParametersContent_T is equal to the array Content and a_AttachPaths_T to the array Attachments

Mailmerge:

`Prepare the mailsend parameters first
$error_L:=ozWR_eMailMngr ("Parameters_Set";wr_Area;->a_ParametersContent_T)

You can ask ozWR_eMailMngr for the parameters like this
$error_L:=ozWR_eMailMngr ("Parameters_KeywordsGet";wr_Area;->a_ParametersNames_T)

The resulting list is shown on the picture of the example database. First 3 Parameters are mandatory, others are optional. If you fill up, SMTP_User, SMTP_Password must be passed too.

`Now for every record in selection
For($i;1;Records in selection([Table]))
  `prepare Mailto
  $error_L:=ozWR_eMailMngr ("Parameters_Mailto";wr_Area;->[Table]Mailto)
  `no attachments
  $error_L:=ozWR_eMailMngr ("eMail_Send";wr_Area)
  `with attachments change the previous line into
  $error_L:=ozWR_eMailMngr ("eMail_Send";wr_Area;->a_AttachPaths_T)
 `depending on error=0, fill the log or archive or whatever is appropriate
  NEXT RECORD([Table]))
End for

Attachments in Temporary folder will automatically be deleted after sending. Other attachments are untouched.

Im not sure, if I like that: optional parameters in between parameters. But it saves a lot of coding for a single mail and for mailmerge too.

Handling errors

If ($error_L#0)
  `this is silent, delivers error-text for the submitted error
  $err_L:=ozError_Tool ("GetError";->$errorText;$error_L)
  `Alert for Designer and Administrator only by default
  ozAlert_Tool ("Error";Current method name;$errorText;$error_L)
End if

Taking care of

If you know about HTML, it should be easier to estimate which formatting options of 4D Write will work in HTML. To name a few that don't work or don't look nice:

  • no double returns (ozWR_eMailMngr tries to remove those)
  • no header, no footer (they are not converted)
  • no pictures on the page
  • instead of pictures insert HTML-expression of type <img src="valid URL" width="" align="" hspace="" >
  • no tabs
  • ergo no tables done with tabs
  • omit columns
  • use common fonts, otherwise it might look more different than expected (WebFonts is a HTML5-feature)

Some things really look better in HTML than in 4D Write, like

  • backgroundcolors: page, paragraph, words
  • links of course

Technicalities

  • only 32 KB of HTML-text supported
  • no Base64 included pictures because of the 32 KB-barrier

Its only HMTL 3.2, nothing about CSS and other fancy stuff common these days of HTML5. But it works and Outlook is oldfashioned anyway :-) We can live with that.

You want to have the source-code? No problem! Send a descend amount of $ or € to my PayPal-account: info@mettre.de. Finding out how much?