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!

  • Migrate mail from one server to another with imapsyncMigrate mail from one server to another with imapsync Have you been in the situation where you needed to move everyone’s mail from one provider to another?  It’s a pain to do using the mail client one at a time, but with this guide, you’ll be […]
  • Block account from sending mail WHM/cPanelBlock account from sending mail WHM/cPanel There may come a time when you’d like to block an account / domain on your WHM/cPanel server from being able to send mail. Here’s how you’d get it done!

    We’re going to set up a […]

  • cPanel server – can’t send mail! If you are trying to send mail via webmail and it is not working out, you may have the answer right under your nose.  If you have CSF installed, it is likely blocking port 25.

    You may […]

  • Install Ubuntu / Xubuntu from USBInstall Ubuntu / Xubuntu from USB Installing via USB is much better/easier than via cd/dvd simply because it’s not going to get scratched up, you can easily carry it around with you to loan to friends, etc..

    Let’s set […]

  • Migrate WHM/cPanel from one server to a new one (script)!Migrate WHM/cPanel from one server to a new one (script)! We’ve started a site to house a script that will migrate your full WHM/cPanel server to new hosting. This takes the new WHM/cPanel backup files and will restore them including system […]

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

*