KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Sending correctly formatted 4D Write Pro documents via SMTP_QuickSend
PRODUCT: 4D Write Pro | VERSION: 17 | PLATFORM: Mac & Win
Published On: August 23, 2019

When sending emails that contain specific fonts, styles, and formatting, it is very important to assure that formatting stays consistent between different clients. In this example, a .4wp document will be sent to Outlook on both Windows and MacOS. Generally the first approach would be to send the .4wp doc as HTML using the code below.



C_LONGINT($err;$sessionParam;$port)
C_TEXT($host;$from;$to;$subject;$msg;$user;$pw)

$host:="exchange.4d.com" // your host
$from:="elui@4d.com"
$to:="elui@4d.com"
$subject:="STMP_QuickSend Test Email"
$sessionParam:=4 // 4 = HTML w/o SSL
$port:=587 // your port number
$user:="your_username@4d.com" // your username
$pw:="your_password" // your password

C_TEXT($body)
WP EXPORT VARIABLE(Form.WP;$body;wk web page html 4D;wk normal)
$msg:=$body

$err:=SMTP_QuickSend ($host;$from;$to;$subject;$msg;$sessionParam;$port;$user;$pw)

If ($err=0)
   ALERT("Email sent")
Else
   ALERT("Error: SMTP_QuickSend"+Char(13)+IT_ErrorText ($err))
End if


On MacOS Outlook (correctly formatted):


On Windows Outlook (lost formatting):


Since 4D Write Pro docs saved as HTML will include css classes within the email body, Windows Outlook will unfortunately block the css class formatting. As an alternative, save the 4D Write Pro document as a MIME HTML and change the quicksend session paramter to 8 which formats the body as MIME HTML.

C_LONGINT($err;$sessionParam;$port)
C_TEXT($host;$from;$to;$subject;$msg;$user;$pw)

$host:="exchange.4d.com" // your host
$from:="elui@4d.com"
$to:="elui@4d.com"
$subject:="STMP_QuickSend Test Email"
$sessionParam:=8 // 8 = MIME HTML w/o SSL
$port:=587 // your port number
$user:="your_username@4d.com" // your username
$pw:="your_password" // your password

C_TEXT($body)
WP EXPORT VARIABLE(Form.WP;$body;wk mime html)
$msg:=$body

$err:=SMTP_QuickSend ($host;$from;$to;$subject;$msg;$sessionParam;$port;$user;$pw)

If ($err=0)
   ALERT("Email sent")
Else
   ALERT("Error: SMTP_QuickSend"+Char(13)+IT_ErrorText ($err))
End if


On Windows Outlook (correctly formatted):


Now that the 4D Write Pro was saved as MIME HTML and SMTP_QuickSend formatted body as MIME HTML, the formatting of the document is now consistent in both Windows and MacOS Outlook.