How to Send a File as an Email Attachment Using Linux Command Line

How do I send a file as an email attachment using Linux command line?

None of the mutt ones worked for me. It was thinking the email address was part of the attachment. Had to do:

echo "This is the message body" | mutt -a "/path/to/file.to.attach" -s "subject of message" -- recipient@domain.example

How to attach a file using mail command on Linux?

Example using uuencode:

uuencode surfing.jpeg surfing.jpeg | mail sylvia@home.com

and reference article:

http://www.shelldorado.com/articles/mailattachments.html

Note:

you may apt install sharutils to have uuencode command

sending email in linux as subject and attachment

There are at least a couple of programs that you can use to send a message with attachments:

  1. The mailx program on my Linux system has a -a option for attaching files as MIME parts:

    echo Test body | mail -s "Test subject" -a test.txt test@example.com
  2. Mutt will also do this:

    echo Test body | mutt -s "Test subject" -a test.txt -- test@example.com


Related Topics



Leave a reply



Submit