Use Word Mail Merge to email attached PDF's

"You can use a mail merge to send new product letters or faxes to your top 1,000 customers, notify employees about their vacation balances in personalized e-mail messages, produce labels or envelopes for customer mailings, or create a directory of your sales force." - Microsoft quote.

And now you can email those documents as a personalized PDF, using pdfMachine!

August 2016 - Windows update bug : MS16-098

A Windows update published by Microsoft on August 9, 2016 has a known issue of "After you apply this security update and you print multiple documents in succession, the first two documents may print successfully. However, the third and subsequent documents may not print." The Microsoft documentation is here. Microsoft have since solved this problem. If you still experience the problem then you need to install the appropriate Windows update or update your pdfMachine version to 14.92 or later.

Step 1 - Create/Open a mail merge Word document

There are many explanations on the web and in the Microsoft Word help on how to create a mail merge document.

The Microsoft Word help on mail merge is excellent.

Microsoft has a mail merge "how to" for Word 2003 users here:

In Word 2003, Microsoft has a wizard that makes things easier. This is invoked by selecting "Tools->Letters and Mailing -> Mail Merge" from the Word menu.

The "Show Mail Merge Toolbar" is a handy option to have selected.

Step 2 - Select PDF Mail Merge from pdfMachine Word toolbar

Step 3 - Mail Merge Wizard

The following dialog will pop up.

Mail Merge Test Mode

If ticked, test mode is enabled.  There are two types of test mode:
* Dont send any emails, just generate the PDF files. CC and BCC entries will also be ignored.
* Send all emails to one particular address, overwriting the email address in the merge data. 

It is strongly recommended users do a test to make sure everything is as expected before doing a "real" merge.

Merge Field to use for "to" address

pdfMachine has to know where to get the destination  or "to" email address from for each email sent. This is the name of the merge source data field.

Save mail merge files

If a directory is specified then the merge Word documents and resulting PDF's are saved to this directory.  If a directory is not specified then a temporary directory is used and the files are removed after the process is complete.

Mail Merge PDF Security Settings

This button invokes the following dialog.  It allows for unique passwords to be set for each PDF.  The passwords can be taken from the contents of merge fields or the same password can be set for each PDF.  A typical  use would be to encrypt the PDF with an open password based on a merge field (e.g. account_number) and hard code a permissions password.

mail merge security settings

Step 4 - Final Email Settings

This is the last configuration window before the merge begins.

The "Carbon Copy" field to be used in the emails.

The "Blind Carbon Copy" field to be used in the emails.

PDF Attach
The name the attached PDF file will have.

Extra Attach
Any other files you wish to attach to the emails can be setup here.

Email send method to use.  Each method has its pros and cons and whats best for you will depend upon your environment.

Extended MAPI
If you have Microsoft Outlook installed, the best method to use will be Extended MAPI, as it will allow HTML emails and will not prompt you.

This also works well, but is harder to configure and you need an SMTP server somewhere.

Simple MAPI
Does not work well with Microsoft Outlook, but may work well with other email clients.  Simple MAPI does not support HTML emails.

This method (not Outlook express) works well on early versions of Outlook, however modern versions of Outlook display annoying security dialogs that need to be acknowledged for each email sent.

Customization & Personalization of CC, BCC, Body, Subject, PDF attach from merge data

It is possible to embed values from the merge records in the text or html email. To do so, surround the field name with curly braces.

e.g. {address}  or {firstname}

The name must match exactly the merge field name. Where there is a space in the merge field name you need to put an underscore in, for example a merge field of "First Name" should be referred to as {First_Name}.

This will work for the CC, BCC, Subject and PDF attach fields as well.


Step 5 - Review the results, your done!

It may take a while to send all your emails, but when finished you will see the results dialog.