Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

1> I want to embed below Perl script in BASH script, and the Message should read from a message.txt file. How to realize this?

  use Mail::Sendmail;

  %mail = ( To      => '',
            From    => '',
            Message => "This is a very short message"

  sendmail(%mail) or die $Mail::Sendmail::error;

  print "OK. Log says:\n", $Mail::Sendmail::log;

2> How to attach log files via Perl script?

share|improve this question
up vote 2 down vote accepted

If you are going to do it in a bash script, then maybe you can do without Perl. In your bash script have something like:

mutt -F $HOME/ -x -a attachment.file -- < message.txt

This needs mutt and you can have a custom .muttrc file ($HOME/ in this case) to control the From: header:

my_hdr From: "Me Here" <>
my_hdr Reply-To:
share|improve this answer
Great! This answers my another question: how to change sender address on the fly using Mutt. But I am now facing another problem: mutt -s "subject here" < /dev/null Error sending message, child exited 67 (User unknown.). This command worked well before I edited (but not modified) /etc/mail/local-host-names file. – Andrew Mar 28 '12 at 13:43
Try mutt -x -s "subject here" < /dev/null. Could it be that is listed in local-host-names but the user does not exist on the system? – adamo Mar 28 '12 at 21:05

The way @adamo told works fine, here's another, perhaps more performant one if there are lots of recipients:

cat message.txt | mail -a 'From:' -a 'To:' -s 'Subject for the message'
share|improve this answer
I tried this command and get error message mail: invalid option --a. – Andrew Mar 28 '12 at 13:25

Your Answer


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.