22

My requirement is to attach all the .csv files in a folder and send them in a single mail.

Here is what have tried,

mutt -s "subject" -a *.csv -- abc@gmail.com < subject.txt

The above command is not working (It's not recognizing multiple files) and throwing the error

Error sending message, child exited 67 (User unknown.).
Could not send the message.

Then I tried using multiple -a option as follows,

mutt -s "subject" -a aaa.csv -a bbb.csv -- abc@gmail.com < subject.txt

This works as expected. But this is not feasible for 100 files for example. I should be able use it with file mask (as like *.csv to take all csv files). Is there is any way we can use like *.csv in single command?

Thanks

AnFi
  • 10,493
  • 3
  • 23
  • 47
Mariappan Subramanian
  • 9,527
  • 8
  • 32
  • 33
  • 1
    What version of mutt are you using? A command like your first attempt worked for me with my copy compiled from a recent version of the mercurial repository, but support for that started with the 1.5.15 release. – qqx Jun 27 '13 at 12:57
  • @qqx Oh is it? It's great then. Am using Mutt 1.4.1.. – Mariappan Subramanian Jun 27 '13 at 13:26

4 Answers4

31

Mutt doesn't support such syntax, but it doesn't mean it's impossible. You just have to build the mutt command.

mutt -s "subject" $( printf -- '-a %q ' *.csv ) ...

The command in $( ... ) produces something like this:

-a aaa.csv -a bbb.csv -a ...
1

Here is the example of sending multiple files using a single command -

mutt -s "Subject" -i "Mail_body text" email_id@abc.com -c email_cc_id@abc.com -a attachment1.pdf -a attachment2.pdf 

At the end of the command line use -a for the attachment .

Some linux system have attachment size limit . Mostly it support less size .

Syscall
  • 19,327
  • 10
  • 37
  • 52
prashant bade
  • 71
  • 1
  • 2
0

I'm getting backslash( \ ) Additionally

Daily_Batch_Status{20131003}.PDF
Daily_System_Monitoring{20131003}.PDF

printf -- '-a %q ' *.PDF
-a Daily_Batch_Status \ {20131003 \ }.PDF -a Daily_System_Monitoring \ {20131003 \ }.PDF
zaerymoghaddam
  • 3,037
  • 1
  • 27
  • 33
  • Slashes are escaping the curly brackets, what concerns me more are the spaces. Otherwise providing filenames with properly escaped characters is fine. – McKean Oct 06 '20 at 09:58
0
#!/bin/bash

from="me@address.com"
to="target@address.com"
subject="pdfs $(date +%B) $(date +%Y)"
body="You can find the pdfs from  $(date +%B) $(date +%Y)"
# here comes the attachments 
mutt -s "$subject" $( printf -- ' -a %q' $PWD/*.pdf ) -- $to <<EOF 
 Dear Mr and Ms,


 $(echo $body)
 $(cat ~/.signature)
 EOF

but it does not work with escape characters in file name like "\[5\]" which can come in MacOs. I created as a script and collect needed PDFs in a folder and just run the script from that location. So monthly reports are sent... it does not matter how many pdfs (number can vary) but also there should be no white space.