Jump to content

Sending HTML-formatted email in Outlook


Zardoz

This topic is 6077 days old. Please don't post here. Open a new topic instead.

Recommended Posts

For those of you who are not intimidated by the prospect of adding HTML tags to your FileMaker databases, here's a technique for generating HTML-formatted email in Microsoft Outlook that works with versions of FMP at least as far back as 3.0.

Actually, it's really not that complicated. You apply the HTML tags in a SetField script step that sets the body or message of the email, using a global field. In this way, the tags do not actually need to be in any of the records. This works very well if you are generating your email by looping through records in a foundset--you only have to do the HTML coding once as part of your SetField script step. For this example, let's call this field gtEmailBody (a global text field).

After gtEmailBody is set, then export this field only to a .htm document on your C: drive (e.g., C:SampleEmail.htm). It is important that you specify the full path when specifying the file, because you are going to delete this file later via the Send Event script step.

If your foundset contains more than one record, then it is important that you redefine your foundset so that it contains only one record before performing the export. Otherwise, SampleEmail.htm is going to contain multiple repetitions of the gtEmailBody field--one occurrence for each record in your foundset. This is accomplished by using the Show All Records / Omit Record / Show Omitted Only technique. If it is important to retain the integrity of your foundset (i.e., if you and/or your users need to see all records in the foundset and not just one record after the email is generated), then you can use the New Window option in FMP 7.0 to perform these steps in a new window; in earlier versions of FMP, you could perform these steps in a related file.

Once you've exported the .htm file, the next script step is SendMail. The trick here is to specify absolutely nothing for the Message (body) area of the SendMail script step--do not specify a field or a calculation; instead, select the "Attach file" option and then specify the C:SampleEmail.htm file.

Intuitively, you might think that you should specify the Message to be the gtEmailBody field, but doing so will just display the exact contents of the gtEmailBody field in the body of the email without rendering the HTML tags.

When you use the attach file option without specifying anything for the Message, and if the attached file is in the .htm format, then the contents of the file display in the body of the email...and the HTML is fully rendered!

You can add a final cleanup step to delete the C:SampleEmail.htm file so that no trace is left on the client machine. Using the SendEvent (or SendMessage) script step, type the following text: cmd /c del c:SampleEmail.htm.

In summary, here is the main sequence of steps in your script (you may need to add other steps to generate and/or sort your foundset first):

1. SetField: this is where you set the gtEmailBody field and embed the HTML tags;

2. Export: ensure that the foundset consists of only one record and then export the gtEmailBody field only to C:SampleEmail.htm file;

3. SendMail: leave the Message area completely blank (you can use the To, CC, BCC and Subject areas) and instead select the Attach file option and specify the C:SampleEmail.htm file.

4. SendEvent: specify cmd /c del c:SampleEmail.htm to delete the file.

Using this technique, the full gamut of HTML coding is available--the emails that you generate can feature tables and style sheets.

A minor artifact of using this method is that the body of the resulting email begins with two "extra" blank lines and one HTML horizontal rule, which are easily deleted before you send the email. If anyone can find a way so that this artifact does not appear, then please post here.

Hope some of you find this useful.

Link to comment
Share on other sites

  • 2 months later...

For this to work properly, when you specify the output file for the export function in FileMaker, name the file with a .htm extension but specify tab-delimited file format. I haven't tried all file formats, but specifying HTML or sylk does not produce the desired results.

Link to comment
Share on other sites

  • 10 months later...
  • Newbies

I am a bit confused and I hope you can clear this up for me. Your topic is exactly what I want to do but here is my confusion:

1. I have a pre-formatted HTML file I created in DreamWeaver. In this file I have added <> tags where I want my data to go. Once I copy and paste this HTML code into the global field, how do I replace the <> tags with the actual record data?

Jay

Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...
  • Newbies

Anyone know a trick to get this to work on a Mac? I've tried Entourage and Mail, but both just attach the HTML document. It looks great, but I need it in the body.

Also, with 9, you can use Get (TemporaryPath) to store the document in the temp folder.

Link to comment
Share on other sites

This topic is 6077 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.