In this article, we will learn how to send an email with a file attachment using the mail command in Linux. This program is not available by default, and can be installed in Debian and Red Hat-based distributions using:.
Similarly, to attach a file with the mail , the argument '-A' can be used:. To send the email to multiple recipients, simply specify the multiple Email IDs separated by a comma.
To include a text file as the message body of the Email, instead of using echo for the same, you can redirect the text of a file to the command as shown below:. Today we have seen a way to send an Email from the Linux command line along with an attachment.
Seiti Seiti 2, 2 2 gold badges 21 21 silver badges 33 33 bronze badges. Add a comment. Active Oldest Votes. Example using uuencode: uuencode surfing. Improve this answer. Pipo 3, 34 34 silver badges 38 38 bronze badges. Jon Jon Is uuencode a "default" GNU tool? My box doesn't seem to have it. The reference article was really useful! Seiti: uuencode is a part of sharutils, and it is GNU software. Ubuntu package is called sharutils, too. This works only for recipients which allow uuencoded attachments — Stefan Schmidt.
This is a good workaround for an ecosystem which is stuck in the early s but the preferred solution in the modern world is to switch to MIME. The solution with mutt does that nicely and reasonably portably. Show 3 more comments. Not really accurate. There are versions of mail which support this, but they are certainly not "plain old mail " but rather, some modernized version or variant. It would help if you specify which version you are using, on which platform.
This is on ubuntu From memory, it also works on centos 6, ubuntu To make it not require user interaction: echo This is a test mail -a doc. Show 2 more comments. Order of arguments was different.
What worked was: echo mutt admin domain. I am using mutt version 1. It works for me to send log from unix to mail server. Thanks — Hongtao. From the mailx man page: -a file Attach the given file to the message. Pretty easy, right? David Winslow David Winslow 8, 1 1 gold badge 29 29 silver badges 27 27 bronze badges. Sorry this didn't help. Thanks for your feedback. I need to open an email from the command line and automatically attach a file I can do this:.
It gives me an error saying: "The command line argument is not valid. Verify the switch you are using". I don't quite understand why it's not working the way it should, everywhere I look people are saying that works without a problem.
When the email opens, the "attach file" button is greyed out. As soon as I click somewhere in the email window, it re-enables that button Not sure if that's going to make a difference, but it'd help if I could get some help with this.
0コメント