I'm doing my first steps with Mutt (with msmtp in Slackware 13.1).
I'm already able to send mail with attachments like so:
cat mail.txt | mutt -a "/date.log" -a "/report.sh" -s "subject of message" -- myself@gmail.com
I would like to define the files to be attached in another file and then tell Mutt to read it, something like this:
mutt -? listoffilestoattach.txt
Is it possible? Or there are similar approaches?
You can populate an array with the list of file names fairly easily, then use that as the argument to -a
.
while IFS= read -r attachment; do
attachments+=( "$attachment" )
done < listoffilestoattach.txt
for f in ../*.log; do
attachments+=("$f")
done
mutt -s "subject of message" -a "${attachments[@]}" -- myself@gmail.com < mail.txt
If you are using bash
4 or later, you can replace the while
loop with the (slightly) more interactive-friendly readarray
command:
readarray -t attachments < listoffilestoattach.txt
If, as appears to be the case, mutt
requires a single file per -a
option, then you'll need something slightly different:
while IFS= read -r attachment; do
attachments+=( -a "$attachment" )
done < listoffilestoattach.txt
for f in ../*.log; do
attachments+=( -a "$f")
done
mutt -s "subject of message" "${attachments[@]}" -- myself@gmail.com < mail.txt
Using readarray
, try
readarray -t attachments < listoffilestoattach.txt
attachments+=( ../*.log )
for a in "${attachements[@]}"; do
attach_args+=(-a "$a")
done
mutt -s "subject of message" "${attach_args[@]}" -- myself@gmail.com < mail.txt