Cron – Send simple HTML email from command line

automationcronemail

I have a cron job which produces a list of resource, expiration date and the days until expiration. The report produces a CSV file. I attach this to the a message using mutt -a report.csv.

I also want to include information in the body of the email. I use gawk to format this into clean lines and add this to the body. It looks something like this:

Resource                                 Expiration Date           Days  
======================================== ========================= ========

resource one                             Oct 11 2009 07:59 PM      3    
resource two                             Nov  3 2009 07:59 PM      22     
resource three has a longer name         Nov  6 2009 07:59 PM      28     
rscrc 4                                  Dec  8 2009 07:59 PM      58     
you get the point                        Dec 17 2009 07:59 PM      66     
www.blockbuster1.smartsubs.net           Dec 23 2009 07:59 PM      70     

(yes, I fudged the dates and expiration, they don't add up in this example)

The problem is that most of the recipients do not have their email clients configured to show plain text email using a fixed width font. So, for them, it looks like this:

Resource Expiration Date Days
======================================== ========================= ========

resource one Oct 11 2009 07:59 PM 3
resource two Nov 3 2009 07:59 PM 22
resource three has a longer name Nov 6 2009 07:59 PM 28
rscrc 4 Dec 8 2009 07:59 PM 58
you get the point Dec 17 2009 07:59 PM 66
www.blockbuster1.smartsubs.net Dec 23 2009 07:59 PM 70

Are there suggestions for how to easily format this text in email so that is forced into a fixed width font? I have flexibility to install new command line tools on this server

Best Answer

If you have a sufficiently recent version of mutt I believe you can do something like this.

mutt -e 'set content_type="text/html"' -a file.csv user@example.org -s "subject" < index.html

index.html will be the html body of your message.