Sending bulk HTML emails with perl

First of all, I have to warn you that using HTML in emails is almost always inappropriate. Use plain text. If you have to send HTML, than send it as an attachment.

For those cases, where HTML message has to be sent and there is no choice in the matter, here is a small perl script –

Edit a few lines at the beginning of the file to suit your needs. From address and Subject line must be changed. Locactions of two files – list of recepients and the body of the message – can be either specified on the command line or will be taken from default values hardcoded in the script.

Run the script as: message.html recepients.txt

If you changed the location of data files or if you are using defaults, than you don’t have to pass any arguments to the script.

List of recepients is expected to be a comma separated list of names and emails. An example file could look like this:

You There,
Him Somewhere,

Message body file should contain all your HTML, CSS, JavaScript and whatever else is that you want to send. Here is an example file for you:

<H1>Hi there!</H1>
<DIV>This is an HTML message.</DIV>

It is easy to change the script to send plain text messages instead of HTML. Just change the line that specifies Content-Type as “text/html” to “text/plain”.

3 thoughts on “Sending bulk HTML emails with perl”

Leave a Comment