Mutt for html body and multiple html & pdf attachments

Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Mutt for html body and multiple html & pdf attachments
# 1  
Old 12-05-2012
Mutt for html body and multiple html & pdf attachments

Hi all:

Been racking my brain on this for the last couple of days and what has been most frustrating is that this is the last piece I need to complete a project.

There are numerous posts discussing mutt in this forum and others but I have been unable to find similar issues.

Running with RHEL 5.5, mutt, perl 5.8.8

The issue is sending emails from command line using mutt. These emails can have 0 attachments to 5 attachments that can be a mix of html and/or pdf. Sending an email with html body/no attachments was simple;

system("/usr/bin/mutt -s \"Support\" -- \"$cust\" < $body");

Works, no problems.

When the -a options are included for the attachments I am still able to have the mail sent and it is received with an html body but the attachments become in line with the body making them unusable. If I add the
-e my_hdr Content-Type:text/html
then the attachments are received fine but the body is plain text with all of the html markups in view.

I can add the
-e my_hdr Content-Type:text/html
on the command line or in .muttrc, same effect. An example of the CLI;
system("/usr/bin/mutt -e \"my_hdr Content-Type:text/html\" -s \"Support\" @attach -- \"$cust\" < $body");


How can I do this? It seems like I need the
my_hdr Content-Type:text/html
off for the body of the email and then to turn it on for the attachments.

I was using MIME::Lite in a perl-cgi script but when the pdf attachments wouldn't work I was able to track it down to the
. There are numerous problems with pdf attachments originating from perl-cgi using the MIME::Lite module, mainly they would arrive in a corrupted state and not properly decoded making them unusable. The html attachments were fine.

If at all possible I want to avoid having to install another package. My feeling is that I will encounter similar issues other clients like mpack. Plus they are not installed and there are many hoops to jump through to get them installed.

Many thanks!
# 2  
Old 12-05-2012
You need to supply the content type like below, this is a simple example of how it works for me in a perl script:

$mail_type='set content_type="text/html"'

$child_pid = open( MUTT,"|mutt -e ${mail_type} -e ${replyto_name} -e ${replyto_email_address} " .
                        "-s ${subject} -a ${attachment} ${emailrecip}" );
if ( not defined( $child_pid  ) ) {
  print "**Error: Could not open pipe to mutt -- additional error text\n";
  writelog ("ERR Could not open pipe to mutt -- additional error text");
  return 1;
# The $message variable has the embedded html
print MUTT $message;
unless (close MUTT) {
  print "**Error: Could not close pipe to mutt -- additional error text\n";
  writelog ("ERR Could not close pipe to mutt -- additional error text");
  return 1;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Attach multiple index.html file using mutt

Hi I want to attach multiple index.html, index_v2 file using mutt command basically i want first index.html and then index_v2.html file as a body in email , these html files are test reports I am using following command , but it is over writing , any help appreceated ;) mutt -e... (2 Replies)
Discussion started by: madankumar.t@hp
2 Replies

2. Shell Programming and Scripting

SQL query output convert to HTML & send as email body

Hi , I have a sql query in the unix script ,whose output is shown below.I want to convert this output to HTML table format & send email from unix with this table as email body. p_id src_system amount 1 A 100 2 B 200 3 C ... (3 Replies)
Discussion started by: jagadeeshn04
3 Replies

3. Shell Programming and Scripting

Mail sending with multiple attachement(pdf and csv) with html content from Linux

Hi, We have a requirement to send multiple attachment(pdf and csv) along with html content in a single mail. For that we are using uuencode. It is working for single pdf attachment and html content. But we are unable to send both pdf and csv attachment with html content. Below is the script.... (5 Replies)
Discussion started by: dholea
5 Replies

4. Shell Programming and Scripting

Issue to attachment with HTML body

HI Team, I used below code to get attachment with HTML body. i having21062013.csv file . but i am getting junk .csv file. Can you please help me out. export export SUBJECT="Test Waiver Code email" export BODY=test.html export ATTACH=21062013.csv... (4 Replies)
Discussion started by: Jewel
4 Replies

5. Shell Programming and Scripting

Multiple attachments using mutt

I am trying to attach multiple files using mutt command, and all file names to be attached are taken from a flat file. and mutt command is called from a bash script when : 1. Script execution is completed. 2. Script execution is interrupted for some reason. ... (8 Replies)
Discussion started by: Shaishav Shah
8 Replies

6. UNIX for Advanced & Expert Users

HTML and attachment using mutt command

Hi All, I want to attach the file as well send html content in the mail body using mutt command or any other command.(uuencode is not present). Please help me. Thanks in advance (1 Reply)
Discussion started by: arukuku
1 Replies

7. UNIX for Advanced & Expert Users

Email with multiple attachments & HTML body

I have a html file: # cat sample.html <html> <body> Sample HTML file</p> </body> </html> And I have two excel sheets (sheet1.xls & sheet2.xls) I want to send an email by having the sample.html as the message body and two spreadsheets as the attachments. I tried using the below command:... (12 Replies)
Discussion started by: BHM
12 Replies

8. Red Hat

Send HTML body and HTML attachment using MUTT command

Hi there.. I need a proper "mutt" command to send a mail with html body and html attachment at a time. Also if possible let me know the other commands to do this task. Please help me.. (2 Replies)
Discussion started by: vickramshetty
2 Replies

9. Shell Programming and Scripting

Sendmail with html attachment and html body

Hi folks, I have a perl script which sends out email after successful completion of job as inline html, I want to send it out as two parts now as html inline and html attachment. see the attached script. Thanks in advance (1 Reply)
Discussion started by: sol_nov
1 Replies

10. Shell Programming and Scripting

Perl - Convert html to pdf - PDF::FromHTML

Hi, I am trying to convert html to pdf using perl module PDF::FromHTML, am getting the error as given below. not well-formed (invalid token) at line 2, column 17, byte 56 at C:/Perl/lib/XML/ line 187 at C:/Perl/site/lib/PDF/ line 140 The perl code is as given... (2 Replies)
Discussion started by: DILEEP410
2 Replies
Login or Register to Ask a Question

Featured Tech Videos