4

I have a requirement where I need to send two files A and B . The file A's content should be displayed as in-line or body of the mail and file B as an attachment.

Is multiple attachment using mutt is possible?

The command

 echo "Hello everyone " | mutt -s 'My mail ' abc@gmail.com -a myFile.txt 

is writing Hello everyone as body of the mail and myFile.txt as an attachment(inline).

Both of my files A and B are dynamically generated, so I cannot have an echo statement.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
Rajeesh
  • 51
  • 1
  • 1
  • 5
  • When you say "files A and B are dynamically generated" does that mean you never a real file on the disk anywhere? – Aaron Digulla Feb 25 '14 at 13:01
  • those are generated by a shell script. The shell scripts calls some plsql procedure to generate report files(file A and B). – Rajeesh Feb 25 '14 at 13:02

2 Answers2

4

It's actually very simple:

mutt -s 'My mail ' abc@gmail.com -a report1.txt < report2.txt

If you had two scripts to create the reports, you could use pipes (i.e. no files would be created on disk):

script2 | mutt -s 'My mail ' abc@gmail.com -a <(script1)
Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • Just a question, when you pipe, don't you actually create a file? That's why stdin, stdout and stderr are called file descriptors – miraunpajaro Aug 19 '21 at 12:47
  • @miraunpajaro No, you don't. They are called file descriptors, because they refer to something that can be **used** as a file, which might or might not **be** an actual file. In this case when mutt tries to read the data, script2 generates them. While mutt is processing the data, script2 is paused. – Vojtech Kane Jan 04 '22 at 16:31
1
cat A | mutt -s 'My mail' abc@gmail.com -a B

If the shell script prints file A's content to standard output, like this:

script >A

then you can use tee to print both to the file A and into the pipe to mutt:

script | tee A | mutt -s 'My mail' abc@gmail.com -a B
SzG
  • 12,333
  • 4
  • 28
  • 41