mutt command with multiple attachments in single mail unix
Asked Answered
B

4

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 -- [email protected] < 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 -- [email protected] < 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

Boraginaceous answered 27/6, 2013 at 11:54 Comment(2)
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.Rosalindrosalinda
@Rosalindrosalinda Oh is it? It's great then. Am using Mutt 1.4.1..Boraginaceous
V
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 ...
Veracity answered 27/6, 2013 at 12:2 Comment(0)
D
1

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

mutt -s "Subject" -i "Mail_body text" [email protected] -c [email protected] -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 .

Deserving answered 4/3, 2021 at 18:36 Comment(0)
K
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
Kaz answered 3/10, 2013 at 20:14 Comment(1)
Slashes are escaping the curly brackets, what concerns me more are the spaces. Otherwise providing filenames with properly escaped characters is fine.Matsumoto
T
0
#!/bin/bash

from="[email protected]"
to="[email protected]"
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.

Tholos answered 16/11, 2022 at 15:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.