You ever want to fire off a quick email and think to yourself, man I wish I could type out some stupid code to send this rather than simply clicking a button? You probably haven’t but it’s still cool to try. It is actually a fast way to send a quick email to yourself with a reminder or something.
So the first step is making sure you have the mailutils package installed since that is the way I think it is the easiest to send email from the terminal.
To install it:
sudo apt-get install mailutils
Now you are ready to send an email from the terminal using this simple command:
mail -s "subject line here" firstname.lastname@example.org
After you hit return/enter the next line will start with “cc:” you can type any additional email addresses here that you wish to carbon copy to the email then press return/enter.
If you don’t want to carbon copy any other party on the email then just leave that line blank and press return/enter.
You will then have a blank line to write the body of your message. You may write several lines in the body using the return/enter key: the email will not actually send until the final step. If you write too much on a single line it may bring the cursor back to the beginning of the line and start writing over your text so watch out for that.
So at this point your terminal will look something like this:
mail -s "Subject of Email" email@example.com cc: Hello, How are you my fine sir? I hope this email finds you in good health. From me
When you are ready to send your message press enter to start a new blank line and the press CTR+D. This will send the message. It may take a little bit of time to actually send so don’t be surprised if it doesn’t immediately shoot the email out. It literally takes like 2 minutes to send on my computer right now*.
By default the email will be sent from the name of your computer. ex. Mike@mypc2089
If you want to specify a from name and address you must enter the first command line like this:
mail -s "subject" firstname.lastname@example.org -afrom:email@example.com
If you just want to send a quick one-liner email you can use this command:
echo "This is the one line of the body." | mail -s "subject" firstname.lastname@example.org
You can put -afrom at the end of that command as well if you would like.
*if you are curious why it takes so long to send an email it is because you are sending the email from an unknown domain or unqualified hostname. You can find your hostname by typing hostname and then you can update it in “/etc/hosts” file: nano /etc/hosts. If you really care that much then you probably aren’t reading this post though.