Site icon Leonid Mamchenkov

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 – send_html_mail.pl

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:

send_html_mail.pl 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,you@there.org
Him Somewhere,him@somewhere.net

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:

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

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”.

Exit mobile version