0
mailx -a 'Content-Type: text/html' \
      -s "Body" \
  < index.html "foo@example.com"

I'm trying to send an email using a mailx command line. The above command is working fine to send body as html file.
But along with it I also want to send an attachment. Is it possible to send an attachment and body as a file together? How to do it?

tripleee
  • 175,061
  • 34
  • 275
  • 318
nnrr
  • 11
  • 2
  • What works in `mailx` depends on which version you are talking about. https://stackoverflow.com/a/48588035/874188 has an exposition of this Tower of Babel. – tripleee Jul 23 '22 at 07:28
  • There's a limit to how complex MIME structures it makes sense to specify serially on the command line. This is approaching the point where a small Python script might start to look like a better solution. – tripleee Jul 23 '22 at 07:35

1 Answers1

1

I found a solution using mutt. Here is the command:

mutt -e "set content_type=text/html" \
     -s "Your subject" to@domain.com \
     -a attachfile.txt < index.html

The content in the file index.html will be shown in the body of the mail. You can attach any number of attachments with -a <file1> <file2>

tripleee
  • 175,061
  • 34
  • 275
  • 318
nnrr
  • 11
  • 2