1

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

e.g. filenames.txt has:

/path/file1
/path/file2
/path/file3
/path/file4

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

2

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.

0

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

/path/to/file1
/path/to/file2

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.