Write Pro Read Email

With version 16 we were using the old 4D write plug-in in conjunction
with write pro to read incoming emails. We did this by using the old
plug-in to create an HTML document

$vlWriteArea:=WR New offscreen area

WR OPEN DOCUMENT ($vlWriteArea;$asEnclosureList{0};wr HTML 4
document) //HTML

Then converted this so that we could use the document with write pro By saving the HTML as a native 4D write document then importing

WR SAVE DOCUMENT ($vlWriteArea;$asEnclosureList{0};“4WR7”)


//save body

$wpEmailBody:=WP Import document($asEnclosureList{0})

WP EXPORT VARIABLE($wpEmailBody;$vsEmailBody;wk web page html 4D)
//wk normal

The problem is in version 17 we do not have the old plug-in therefore we cannot see why to import the HTML into a new write pro document. If we Load the HTML from a text file on the disk

$vtxtDocument:=Document_LoadFile (vs32BodyDocumentID)
If (Test path name($vtxtDocument)=Is a document)
$vsEmailBody:=Document to text($vtxtDocument)
End if

End if
wpEmailBody:=WP New($vsEmailBody)

We get an error

Error when executing the method “Email_InputLoad” at line number 156

4D Write Pro import has failed to complete.
Error code: 106 (wri1)
4D Write Pro import has failed to complete.
component: ‘wri1’

Has anyone got any idea how to open html file with write pro ?

Can somebody please clarify. According to docs we can create a new
write pro document from valid html.

If the source parameter is used, the new 4D Write Pro object will be
filled with the contents of the source. You can pass:

a string parameter: In this case, you pass a 4D HTML source,

However we get this error every time

4D Write Pro import has failed to complete.

Error code: 106 (wri1)
4D Write Pro import has failed to complete.

first, are you sure $vsEmailBody is indeed populated with the document content?
when you omit the encoding option or Document to text,
it will assume that the encoding is not Unicode, unless there is a BOM.
it will also make some assumptions about the line separator.

note that the command does not support ERROR or OK,
so you need to check the length to know if the commands actually worked.

finally, please notice that 4D Write Pro only supports correct HTML (read XHTML). If the HTML has errors it will not work.

In fact, 4D Write Pro is not designed to be used as HTML editor or HTML viewer, it is designed to handle text processing.
Instead of a proprietary binary format we decided to use a text based well known format, XHTML, to store the documents.
As long as the opened document follows the same rules as 4D Write Pro, it can open it. If the document does not conform, it cannot open it.

If you want to display any received Email (and emails are formatted in many strange ways), it could be a better choice to use a HTML viewer, such as TinyMCE.
As alternative you could look for a tool to convert the received email to XHTML, this will drastically increase the chance to open it with 4D Write Pro.

Hello Miyako,

Thank you for reply. The variable is populated with valid HTML. I
saved the HTML to disk we are testing with a Google emails sent to our
server from Google. Tried options such as $vsEmailBody:=Document to
text($vtxtDocument;“UTF-8”;Document with CRLF) etc.

We also tried your plugin gmime which works fine however the email
html body is similar with the html body extracted via MSG_Extract so
we still get the same error.

If open body html in web area and call WA get page content then WA get
page content returns html that works for WP New.

WA SET PAGE CONTENT(waTemplate;$html;“file:///”) // set $html as page
content in web area

$html:=WA Get page content(waTemplate)// get back the html

wpEmailBody:=WP New($html)// $html from web area opens without error.

The only difference we can see is that the web area html attributes
inc quotes

Web area which works

<table width="500" align="center" class="body_content_wrapper head_flexible"

Html from gmime plugin or MSG_Extract which causes error

<table width=500 class="body_content_wrapper head_flexible" align=center

As Thomas mentioned below it is a valid html issue but write pro seems very strict in this context.

quick Google search lists several “HTML2XHTML” solutions.

not sure if any would be effective in this instance…

I think there is a demand for a nice and stable html/mime editor in 4d to read, answer and create write emails in 4D. The java tiny mce and other tools are not a good workaround to build an E-Mail client in 4D


I agree and we have been posting about this for a long time. We had it working really well up to V16R6 with 4Dwrite and writepro but now we cant use 4dwrite plugin to convert the incoming mime to writepro xhtml its broken. We are still trying to sort out solution. We have it working using web area but formatting is messed up.

We already have WP EXPORT DOCUMENT supporting output to html so only need corresponding WP Import document to support html import same as 4dwrite .


We have tried a couple of html to xhtml converters such as this one. http://corsis.sourceforge.net/index.php/Html2Xhtml This does allow write pro to open the email body without error however the formatting in write pro is no good despite being valid html and looking ok in browser and web area.

To solve problem we have resorted to using tinymce to handle emails. This is a real issue as we have built a template system inc pdf attachments etc which has been great until v17.


for reference I’ve posted a Tiny based converter on GitHub


Thanks Miyako, Ill have a look at this. We just got TinyMCE working.