shellmutt

Send mail with mutt in shell script file


I am writing the following command in .sh file and it opens the interactive window to ask me to input an email address to send the email. The email is then sent with the attached file without issue.

mutt -s 'risk items' -a file.xlsx

But if I try the following command it fails to send it bypassing the interactive window.

mutt -s 'risk items' -a file.xlsx my_name@company_name.com

Also the second command is working outside shell. Any help to solve this would be appreciated.

The error message is:

my_name@company_name.com: unable to attach file.

Solution

  • Your syntax is incorrect. Look at the output of mutt -h, which should include something like this:

    mutt [<options>] [-Ex] [-Hi <file>] [-s <subj>] [-bc <addr>] [-a <file> [...] --] <addr> [...]
    

    Look at the -a argument, which shows -a <file> [...] --.

    The -a argument expects multiple files. You use -- to terminate the list so that mutt knows you've stopped listing files and are now listing addresses:

    mutt -s 'risk items' -a file.xlsx -- my_name@company_name.com