Friday, May 07, 2004

Mass Mailing

I had wanted to completely rewrite the mass mailing system to allow users to control all the information we have about them. Kind of a profile system where people can update their personal information, subscriptions, contact preferences, and other information. This will tie in quite well with purchasing and workshops once it's completed. Minimal information will be required and collected (though no doubt somebody will want to try and collect more and more once they see how the system works). The best part will be the tie-in with the communications database … unifying two of our biggest contact management systems (big for us anyway).

Sadly I ran out of time to complete this project and had to resort to massive modifications to the current system. It's still disociated from the communications database, but now a lot of the electronic items are tied together better. A user can subscribe/unsubscribe from the various newsletters much easier now (though I still have one more page to adjust). It probably wouldn't take much of an effort to add the ability to subscribe/unsubscribe from the print newsletter … which would be a great stop-gap solution until I have time to complete the larger overhaul.

The majority of the work, however, went into the new mailer. I had to spend a significant amount of time figuring out the format of plain-text and HTML-based multipart/mime mail. Though more "manual labor" is required on the part of the person doing the mailing (that would be me), the new system is a lot more flexible. Plain text mailing basically utilize the same system as before with the CDO NewMail object. I've moved the standard footer portion to the client side so that I could de-couple the mail creation from the actual sending of the messages. This had the benefit of allowing me to set up a preview option where an EML file is created and downloaded (thanks to the content-disposition HTTP header). All this, however, was gravy after spending around two weeks attempting to set up a system that can do multipart mailing as well. A number of considerations had to be made:
  • line length … I wanted to stick to around 69 for URL modification purposes
  • what encoding format to use … I wanted to stay away from quoted-printable to make my life easier; I ended up having to set up QP for the text portion of the message anyway; perhaps I should rethink the current encoding on the HTML portion of the message
  • mime encoding of images and internal reference … I had originally wanted to pre-encode the images and just insert them where necessary, but decided that could cause other problems so I went with dynamic inclusion
The system I ended up with is very nice. There are now two textarea fields, one for the text content, one for the HTML content. Upon making modifications to the text field it automatically generates QP text which is inserted into a hidden field. A standard footers is available for the text content field (inserted at the end of any current content) and is generated based on what list has been chosen. The HTML field accepts the code of a standard HTML document (preferably in HTML 4 format using CSS for styling). Up to 5 images can be attached to the message. Click on the appropriate link and submit the image. The images are base64 encoded and inserted into a hidden form field along with the name. Three options are available for each image: clear it out, check the name, and insert a reference into the HTML. The last option requires the cursor to be at the insertion point and inserts a cid reference to the mime-encoded image. The image ID is generated on form loading. HTML-based e-mails use a template for generation and a file drop into the pickup folder for sending. The mail template is fairly simple and there is an additional template that can be inserted for the images. Text replacement is used to fill out the headers and content of the message.

I'm not sure if the mime boundaries are RFC acceptable, but they seem to work well enough and I'm not overly concerned about running into duplicate boundary identifyers. All tests on the system have gone smoothly. I've already sent out a text-based message and it went off without a hitch. As a matter of fact, it went better than the previous few months because I've finally implemented the new from address with the new system. This had been giving us no end of headaches previously thanks to filters and such. There were no messages stuck in the queue at all … which is a pleasant change.