Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

up vote 2 down vote accepted

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.

share|improve this answer
    
argh - Error in command line: content_type: unknown variable –  Doug Harris Oct 22 '09 at 20:17
    
which version of mutt do you have? I have mutt 1.5.18 on a Ubuntu. –  Zoredache Oct 22 '09 at 20:37
    
I just installed a newer version. It works. Accepted. –  Doug Harris Oct 22 '09 at 20:59
    
more details: I used that set content_type and wrapped my content in pre tags. –  Doug Harris Oct 22 '09 at 21:11

I would say just build an html table using print statements, hacky but works, I have done it before.

Less hacky, would be to use a csv to html table converters. Here is one with awk. You can then just send both html and plaintext, and their reader should use. You will have to look up how to do that with whatever mail library/program you are using.

Either way, I would go with the tables over trying to force the fix width font. I think the table would be more consistent (I don't have any actual evidence of that though).

share|improve this answer
1  
Wouldn't I also need to munge the mime-type header (and possibly others)? Or are most email clients helpful about displaying HTML w/o respect to headers. –  Doug Harris Oct 22 '09 at 19:17
    
Doug: Probably, I don't know very much about that. You might post that as a specific question on stackoverflow in addition to this post. –  Kyle Brandt Oct 22 '09 at 19:22
    
Just tested using pre tag and p style="font-family:courier" and in both cases the HTML tags showed up as plain text as well. –  Doug Harris Oct 22 '09 at 19:27

Couldn't you wrap the whole thing with a p element and an inline style set for a monospaced font and preformatted spacing?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.