0

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?

Andrew
  • 113
  • 1
  • 5
  • 14

2 Answers2

2

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
adamo
  • 6,925
  • 3
  • 30
  • 58
  • 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. – Andrew 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
1

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
Janne Pikkarainen
  • 31,852
  • 4
  • 58
  • 81