Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How to send mail from the command line?

share|improve this question
You can also use pine. –  Kaveh Dec 31 '13 at 3:43

15 Answers 15

up vote 21 down vote accepted

Try to install The Mutt E-mail Client. Other option is using emacs with gnus. Others options available too... IMHO, you should use more details in your questions, or several different answers to your question you will receive :-)

share|improve this answer
Accepted this one since it doesn't require any configuration and is quite user-friendly. –  Olivier Lalonde Nov 13 '10 at 21:00
wait. mutt - user friendly? the craziest one-liner I've read today :) –  Stann Apr 21 '11 at 22:19
  • Install ssmtp Install ssmtp: sudo apt-get install ssmtp

  • Edit the ssmtp config file : gksu gedit /etc/ssmtp/ssmtp.conf

  • Enter this in the file:

  • Enter the email address of the person who will receive your email:

    ssmtp recepient_name@gmail.com
  • Now enter this:

    To: recipient_name@gmail.com
    From: username@gmail.com
    Subject: Sent from a terminal!

    Your content goes here. Lorem ipsum dolor sit amet, consectetur adipisicing.

  • To send the email: Ctrl + D

You can also save the text mentioned in Point 5 into a text file and send it using:

ssmtp recipient_name@gmail.com < filename.txt
share|improve this answer
Why did you use images for text? It would be handy to be able to just copy and paste the config file text. –  Alvin Row Nov 12 '10 at 22:04
Fixed it. I just figured out that I could use html here. :) –  Sid Nov 12 '10 at 22:37
It feels wierd leaving my email password exposed in some file on the computer. Is this safe? –  oadams Nov 13 '10 at 2:50
@oadams not very safe. Use 2-step verification to lower your risk, or use a mail gateway that doesn't require a password, like your ISP's. –  itsadok Mar 25 '12 at 13:54
Don't install ssmtp on a server with postfix installed. Postfix will be removed. Instead, just use sendmail user@example.com < file.txt which will work with either postfix or ssmtp. –  Alistair Buxton Dec 9 '12 at 22:05

Most of the time you shouldn't need to configure an SMTP server you can simply use mail from the commandline (if it's not already present, install with sudo apt-get install mailutils). (Or if you're on a server where sendmail is configured, etc)

marco@dagobah:~$ mail -v marco.ceppi.use@gmail.com
Subject: Hello World!
This is an email to myself.

Hope all is well.

You terminate messages with a . on a single line. That's when mail will prompt you for Cc: enter the information (or leave blank) and mail will then print out additional information on what it is attempting to do, as well as detailing the processing of connecting, transmitting, and receiving data from the mail server.

share|improve this answer
I would append the answer to include "sudo apt-get install mailutils" since it is not present on a clean Ubuntu 10.04 install. Also, terminating the message with a . on a single line didn't work. I had to "Ctrl-D" instead. Lastly, the message didn't go through! –  Olivier Lalonde Nov 13 '10 at 20:40
Edit: the mail didn't go through because of my ISP nevermind. See askubuntu.com/questions/13072/… –  Olivier Lalonde Nov 13 '10 at 20:59
Is there a way to send an attachment with this? My primary usage is to send a file to an e-mail address. –  soandos Mar 17 '13 at 3:46
@OlivierLalonde sudo apt-get install mailutils will install a SMTP server which is postfix, which might be a little overweighted for some people. –  vaab Oct 4 '13 at 7:47
-v option not in my install of mail 2.99.98, also had to use Ctrl+D to end –  markmnl May 17 '14 at 17:53
apt-get install libio-socket-ssl-perl libnet-ssleay-perl sendemail


sendemail -f fromuser@gmail.com -t touser@domain.com -u subject -m "message" -s smtp.gmail.com -o tls=yes -xu gmailaccount -xp gmailpassword 

If you don't want to specify your password in the command line (generally not a good thing to do), you can omit that parameter and sendemail will prompt you for the password... and display it on the screen, but at least it won't be in your command line history.

share|improve this answer
Sending mail from a GMail account using sendmail most certainty very handy. Thank you. –  Mark Tomlin Mar 5 '13 at 17:09

mpack is excellent commandline way of sending file attachments.

apt-get install mpack


mpack -s "file you wanted" ./data.pdf loser@supergoober.cn
share|improve this answer

You need an MTA to send mail. For this, use postfix:

sudo apt-get install postfix

To send email:

echo "test message" | mailx -s 'test subject' myemail@mydomain.com


share|improve this answer
You also need to install mailutils for mailx, right? –  Nick Jul 15 '14 at 5:26

You can send an email from the command line with TelNet or NetCat.

Everything is explained here.

hanoo@hp_laptop% nc 25
220 hp_laptop.localdomain ESMTP Postfix
EHLO man
250 hp_laptop.localdomain
MAIL FROM: <netcat@postfix.com>
250 2.1.0 Ok
RCPT TO: <target@host.com>
250 2.1.5 Ok
354 End data with <CR><LF>.<CR><LF>
This is the body of my mail,
this is the second line...
250 2.0.0 Ok: queued as 9C12E7F404
share|improve this answer
It's a little hard to use SSL when using this method ;) –  iX3 Dec 30 '12 at 23:09

I have never tried it but there is a mail command that can send mail. See man mail.

share|improve this answer

sudo apt-get install sharutils mailutils

uuencode filename filename | mail user@example.com

where filename is the same, it's stands for infile and remotefile

share|improve this answer
sudo apt-get install sharutils for uuencode –  Janus Troelsen Oct 19 '12 at 22:53
mailutils installs mysql! oO –  chmike Apr 24 '14 at 9:15

If you try to send e-mail from a system, whitch does not run an own e-mail-server (i. e. desktop system), you need to install something like nullmailer or esmtp, which forward your local mail to a "real" mail server.

As command line tools you can install mail or mailx (packages mailutils, heirloom-mailx or bsd-mailx). If you need attachments try biabam.

share|improve this answer
mail -s "subjet" -a "attchedfile_name" someone@dest_email.com


cat "afile" | mail -s "subject" someone@dest_email.com
share|improve this answer


sendmail -t receiver@example 

then write your email then press Ctrl+D

share|improve this answer

You can try this:

mail name@mailserver.com -s "Attached file" <<EOF                 

~| uuencode $HOME/filename.txt filename.txt


It works with GNU Mailutils, check the website for more information.

share|improve this answer

You can also install msmtp and follow the instructions described in the ArchWiki

share|improve this answer

protected by jokerdino May 6 '13 at 14:36

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.