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!

  • Search previous commands typedSearch previous commands typed If you want to see a collection of your previous commands used in Linux, you can always type ‘history’ for a listing of them. You can even search through history by grepping for the […]
  • CentOS 7 / RHEL 7 – Open portsCentOS 7 / RHEL 7 – Open ports One of the most common things I do on Linux machines is open ports to test software in a development environment.  In the past, that meant trying to remember (and Googling) cryptic […]
  • Understanding cron job timesUnderstanding cron job times Often, you’ll want to use cron to schedule daily, weekly, hourly (etc…) tasks on your linux system(s). cPanel has a little GUI for it, but since I don’t trust GUIs very often, I like […]
  • 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 […]

  • Manually run ClamAV on cPanel and check every userManually run ClamAV on cPanel and check every user If you’re running WHM/cpanel and want to run a scan on every user manually, perhaps when first installing ClamAV, you’ll want to run this command which is endorsed by cPanel […]

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

*