Send mail via the command line

Rob —  June 2, 2015 — Leave a comment

During your stint as a Linux administrator, you’ll likely want to send mail from the server you are working on. Whether its sending a quick test message or emailing yourself a file, it can be done quickly and easily.

First of all, you might have to install the mail program to be able to send emails from your server.  For example, I installed this on Ubuntu with:

The following command is a very simple way to send an email from the command line.  The email body is echoed and piped to the mail program.  The subject and addressee are arguments to the mail program.

If you want to send a more detailed message, you can type the message in a file and send it like this:

You can use the following command to attach a file to your message.  The -A argument specifies the attachment.  This is handy for sending a file to yourself so you can easily get it on another machine.

That’s all you have to do to send a quick email from the command line!

Related posts from Linux Brigade!

  • Patch your WHM/cPanel machine for heartbleedPatch your WHM/cPanel machine for heartbleed You’ve certainly heard about Heartbleed by now. If not, you can read more about this vulnerability at Heartbleed.com. Continue reading this post to find out if you’re vulnerable, and how […]
  • Migrating from Plesk to cPanel via commandlineMigrating from Plesk to cPanel via commandline If you’re anything like me, you prefer to do things via command line (CLI) rather than relying on a GUI to do most things in Linux. You also realize that while some of us don’t like to use […]
  • Run fsck on a XenServer Virtual MachineRun fsck on a XenServer Virtual Machine You hope that you won’t ever need to, but you may one day need to run fsck on a Linux XenServer VM that won’t boot.. no worries, attach the storage from that VM on another VM and run it […]
  • Back up all of your mysql databases nightlyBack up all of your mysql databases nightly Have you ever wanted to make your own MySQL database backups?  You can use this script I wrote to make a backup of all databases, then save each one in a dated backup directory.  It will […]
  • Untangle your networkUntangle your network Whether you’re the admin of your office network or your home network (or both), it’s always a good idea to have security and order in place. Untangle is software that you can install as […]

No Comments

Be the first to start the conversation.

Leave a Reply

Text formatting is available via select HTML.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url=""> 

*