Bash and mutt

So trying to write a bash script that uses mutt to send various emails. So the following works with no attachment:

cat $email_body | /usr/bin/mutt -s "$msg_subject" $rcpt

However when I try to attach a file I see the following:

cat $email_body | /usr/bin/mutt -s "$msg_subject" -a "$file_to_attach" $rcpt
Can't stat : No such file or directory
: unable to attach file.

Adding “–” before the recipient’s email address works:

cat $email_body | /usr/bin/mutt -s "$msg_subject" -a "$file_to_attach" -- $rcpt

Leave a Reply

Your email address will not be published.