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!

  • Warning: Skipping the data of table mysql.event.Warning: Skipping the data of table mysql.event. Your MySQL script was running great, but then you started getting errors – If you get this warning when dumping the mysql database, it’s not a bug – MySQL did this on purpose because they […]
  • Delete files that are x days oldDelete files that are x days old Sometimes in Linux, you want to clear out older files in a directory. One instance would be if you have a security system and it continuously writes video files to a directory on your NAS […]
  • 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 […]

  • Install XenServer via usb flash driveInstall XenServer via usb flash drive USB Flash drives are getting cheaper and cheaper lately. I just picked up few at staples – 16GB flash drives for just under $8. I like to use them to install Linux – I always seem to […]
  • Change main hostname and IP of WHM/cPanel machineChange main hostname and IP of WHM/cPanel machine One thing you’ll probably run into sometime is changing the hostname and IP address of a cPanel machine.. whether you’re cloning it for a quick start or if you’ve taken it over.. moving it […]

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

*