I need to read list of files from another file and attach them together and send mail.

e.g. filenames.txt has:


Command or script should read from filenames.txt and attach file1,file2,file3 and file4 in email and send.


I recommend you to use mutt to send emails with attachments from scripts:

$ cat mail.txt | \
    mutt -s 'My Subject' \
      -a /path/file1 /path/file2 /path/file3 /path/file4 \
      -- email@example.com

You need to use -- to separate between the attached files and the destination address.


Personally I use mutt to read and send mails. Assuming that your file filenames.txt is:


I would write:

mutt -s "Subject" -a $(<filenames.txt) -- dest@example.com < mailbody.txt

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.