Send emails with attachments

You don’t need a client, you don’t need to have your own email, of course, it’s likely to go into the trash, but if you’re backing up your files occasionally, who cares about garbage?



Echo "have attachment temperature mail" | "here is the title" mailx - s - r [email protected] - a. / attachementfile. Zip at [email protected]

Mac OS

Uuencode. / mysecret_video. Gz video. Gz | mail -s "nice small patches of" [email protected]

The key to becoming an advanced Linux user is to use the command line more than the GUI; More keyboards and fewer mice! With the proliferation of Linux command-line tools, it is possible to use the command line not only to perform administrative tasks, but also to perform non-administrative, actually critical, everyday tasks.

In this article, you’ll learn how to use the mail command in Linux to send E-mail with file attachments.

A prerequisite for

You must have configured your E-mail using SMTP on your Linux machine. This email and server will be used by the “mail” program we are going to learn about today.

Sending E-mail from the command line in Linux The program Mail can be used to send E-mail from the command line as well as file attachments with E-mail. The program is not available by default and can be installed in Debian and Red Hat based distributions using the following command:

$sudo apt install mailutils [on Debian/Ubuntu/Mint] $sudo DNF install mailx [on RedHat/CentOS/Fedora]

The syntax for using “mail” to send an E-mail is as follows:

$echo "email message body" | "subject" [email protected] mail - s

You can see that we are using the echo command to output the message body and redirect this output to the Mail command. This is because the ‘mail’ command reads the message body input from standard input.

Send an email with A file attachment from the command line Again, to use mail to attach files, ‘-a’ can use the argument:

$echo "email message body" | "subject" [email protected] mail - s - A < to attach file >

To send an E-mail message to multiple recipients, simply specify multiple E-mail IDs separated by commas.

$echo "email message body" | "subject" [email protected] mail - s; [email protected], where -a < the file to attach >

To include a text file as the message body of an E-mail, instead of using echo, you can redirect the text of the file to a command like this:

$mail-s "mail subject" [email protected] -a < file to attach > <mailtext.txt


Today we saw a way to send emails and attachments from the Linux command line. There are other programs, such as “mutt” and “Sendmail,” which are similar to “mail” and can be used for the same purpose.