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

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      => 'you@there.com',
            From    => 'me@here.com',
            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

2 Answers 2

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/.muttrc.me -x -a attachment.file -- you@there.com < message.txt

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

my_hdr From: "Me Here" <me@here.com>
my_hdr Reply-To: me@here.com
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" my@company.net < /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. –  beicha Mar 28 '12 at 13:43
Try mutt -x -s "subject here" my@company.net < /dev/null. Could it be that company.net 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: me@here.com' -a 'To: you@there.com' -s 'Subject for the message' you@there.com
share|improve this answer
I tried this command and get error message mail: invalid option --a. –  beicha 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.