Tell Mutt to attach files (listed in file)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 23:08:51

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/33782416/tell-mutt-to-attach-files-listed-in-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!