0

How can I send a file as an attachment via email in bash script, without using mutt and uuencode?

  • 4
    It's kind of weird to tag this mutt when you specifically don't want that.... – mattdm Jun 2 '16 at 15:51
  • sorry, newbie to this kind of forum. – user548682 Jun 2 '16 at 16:25
  • On what operating system (if Linux, what distribution)? The available commands for sending mail differ quite a lot on different unix variants. – Gilles Jun 3 '16 at 21:44
2
echo "Message body" | mailx -s "Subject" -a "/path/to/attachment" somebody@example.com

or

cat "/path/to/messagebody.txt" | mailx -s "Subject" -a "/path/to/attachment" somebody@example.com
  • Thanks for the answer. But I didnt get it work to send as attachment. – user548682 Jun 2 '16 at 16:30
  • Could you be a bit more specific than 'it didn't work'? – DopeGhoti Jun 2 '16 at 17:19
  • mail: invalid option -- a Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ... [-- sendmail-options ...] mail [-iInNv] -f [name] mail [-iInNv] [-u user] – user548682 Jun 2 '16 at 17:22
  • I got this error. – user548682 Jun 2 '16 at 17:22
  • 1
    @DopeGhoti - things that are not the same mailx. There are several different versions of mail/mailx, all with different options and capabilities. On Debian, for example, there are (at least) bsd-mailx, heirloom-mailx, and s-nail packages which provide different versions of mail and mailx. – cas Jun 3 '16 at 2:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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