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!

  • Lock down your phpMyAdmin access! There are a couple of ways that I lock it down.. I won’t get into specifics because I don’t want you (or you!) trying to find it, but I can’t count the number of times I’ve seen an old […]
  • Globally disable directory listing on WHM/cPanelGlobally disable directory listing on WHM/cPanel One of the things that WHM/cPanel servers have on by default is directory listing. This is something you don’t want – but it’s easy to fix!

    1. Log into WHM
    2. Apache Configuration […]

  • Download Linux – Links to 20 popular distributionsDownload Linux – Links to 20 popular distributions I always find myself telling people to just download Linux. This usually follows up with “which distribution” and i’ll recommend a couple but always end with “try a few and see which one […]
  • 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 […]
  • Learn the CSF command line options You have CSF installed and use the GUI to do most things.  (If you don’t have it installed yet, you can read our article on how to install csf).  BUT – knowing the csf (ConfigServer […]

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=""> 

*