Introduction
With SMTPit Pro you can send styled text, formatted in FileMaker, as HTML using the SMTPit_StyledTextToHTML function. This function converts all FileMaker styles such as font, size, bold, italic, color, and more to HTML.
You can use either old style html or CSS for formatting the HTML. There are advantages to both. Old style html will work in just about every email client that can display HTML. However, using CSS is much more exact in its rendering. The problem with CSS is many clients will completely ignore CSS and your message will not be formatted at all. So it is up to you to determine what your target user is and the best approach.
Download Example File
Settings
- Before you can send email from this database, you will need to enter a few settings. At bare minimum, you will need to enter your email host. The default host port is 25, but you may need to change this depending on your email server. If your email server requires authentication, you will need to choose an authentication type and enter your username and password. If your email server requires an SSL connection, you can set the SSL field to the correct SSL type. If you are unsure of which type to use, try both to see which works.
SMTPit Pro will always return information back to you when you make a function call. You can also get a transcript of of the interaction between SMTPit Pro and your mail server by setting the field “Get Transcript” to true.
All of the fields mentioned above are used in various calculations throughout the example database. This approach allows the database to be portable in a sense because the database can be moved to a different computer without losing the settings.
Another approach for storing settings is to use the default values in the SMTPit Pro configuration dialog. In the configuration dialog you can add default headers and footers, and other various settings. These preferences will be stored on your computer only, so if you move a database to a different computer, you will need to visit the preferences dialog to enter your settings. There are advantages to using both methods, and it will be up to you to decide which one will fit your needs.
Need help? Don't know what to use as your Settings or getting errors when trying to send?
Take a look at this article. Access the Plug-in
When using plug-ins (not just ours), they do not add new script steps, but instead add new functions that are available in the calculation engine.
To see a calculation that tells the plug-in what to do, go to the “Scripts” menu, and choose “Manage Scripts” or “ScriptMaker”. Once in Manage Scripts/ScriptMaker, double click on the “Send” script. Note that we are using the “Set Field” script step which consists of two settings. The “Specify target field” button allows you to choose which field you want to set. In our case we want to set the “Result” field. The second specify button is where the SMTPit Pro calculation exists. Click this button to see the calculation used to tell the plug-in what to do.
In this calculation, the plug-in is accessed using the “SMTPit_FunctionName” functions. There are many functions allowing you to do different things such as set the To address, Subject, and etc. For a complete listing of the functions available, see the Functions tab. You can also access the functions in a “Specify Calculation” window by clicking the “View” menu, then selecting “External Functions”, and then scrolling through the list until you find the plug-in name.
StyledTextToHTML Function
SMTPit_StyledTextToHTML( FieldName {; UseCSS {; IgnoreTraits }} )
This function is used inside of the SMTPit_SetBody function as follows:
SMTPit_SetBody( SMTPit_StyledTextToHTML( “Send Styled Text::Body” ; Send Styled Text::UseCSS ) ; “HTML” )
In other words, the styled text is converted to HTML by the SMTPit_StyledTextToHTML function and passed directly to the SMTPit_SetBody function which is set to assign HTML. The UseCSS field determines if the HTML should use old style formatting or CSS.
Take note that the “FieldName” parameter MUST be in quotes because the actual name of the field need to be passed to the plug-in in order to convert the styled text properly.
HTML Preview
The “HTML Preview” field simply uses the “SMTPit_StyledTextToHTML” function in order to convert the styled text in the “Body” field to HTML. The “HTML Preview” field uses a let statement because the “Body” field needs to be referenced so that the html will be updated. This is necessary because the field name that you pass to the SMTPit_StyledTextToHTML function must be in quotes in order for the function to work properly. The “UseCSS” field will also trigger the “HTML Preview” to update. All of this is wrapped in the SMTPit_MergeText function to convert the merge tags into the actual data from the fields for the preview.
As mentioned in the “Merge Fields Email” example, the script that actually sends does not need to include the SMTPit_MergeText function because the plug-in will automatically convert merge fields when sending an email.
The calculation is as follows:
Let ( [ update_trigger_body = Body ]; SMTPit_MergeText( SMTPit_StyledTextToHTML( “Send Styled Text::Body” ; UseCSS)) )
Preview Button
Under FileMaker 11 or below, the “Preview” button triggers a script called “Send Styled Text - Browser Preview”. The script uses FileMaker to export the contents of the “HTML Preview” field into the same folder as this example database. Then it uses the SMTPit_File_GetPath function to determine the path to this database which is used in an Open URL script step.
The end result is you can preview your HTML email in your default web browser.
In FileMaker 12 and above, the HTML preview will automatically be displayed in the Web Viewer object on the layout.
UseCSS
You can use either old style html or CSS for formatting the HTML. There are advantages to both. Old style html will work in just about every email client that can display HTML. However, using CSS is much more exact in its rendering. The problem with CSS is many clients will completely ignore CSS and your message will not be formatted at all. So it is up to you to determine what your target user is and what the best approach is.
Merge Fields
You can use merge fields in the Body field. In fact, you can apply any styled text to the merge field and it will come through in the final email.
For example, the following merge fields:
Name: <<Name>>
Phone: <<Phone>>
Country: <<Country>>Will be merged as follows in your final email messages , assuming the field values are the same:
Name: John Doe
Phone: 123–456–7890
Country: USAView Results
This example has a Send Result field where the Results are shown. This is where the plug-in can give you feedback on what it is doing. If an error occurs, it will report the error in the results field which can help you fix any issues you may be having. It will also report its successes so that you know everything is going as planned. If you have “Get Transcript” set to true on the settings layout, you will also see the interaction between SMTPit Pro and your mail server in the Result field.
Need help? Getting errors when trying to send?
Take a look at this article.How to recreate in your solution
In order to recreate this example in your solution, you simply need to use the SMTPit_StyledTextToHTML to convert your styled text to HTML and then pass it to the SMTPit_SetBody function.
This example uses the following calculation to accomplish this:
SMTPit_SetBody( SMTPit_StyledTextToHTML( “Email::Body” ; Email::UseCSS ) ; “HTML” )
Note, make sure your Body field name is inside double quotes as shown above.
To recreate this in your own solution, you will need to reference the fields in your own database if they are not the same.