Send email from command line using mail command

We are familiar with many graphical platforms to send out emails like Thunderbird, Outlook, Webmail etc. Here I am explaining about a tool used to send emails from the server command line on Linux based systems. It can be used via terminal as well as from bash scripts. 

  1. Installation

    We can install 'mail' tool using the following commands:

    On Centos based OS:
    yum install mailx -y

    On Ubuntu/Debian based:
    apt-get install mailx -y
  2. Once installed, we can send emails using the following commands:

    To send a simple mail with some content in the body:
    $ mail -s “test mail” [email protected]

    The -s option is used for mentioning the subject of the email followed by email address in which we need to send the email. After executing the above command, we need to enter the body content and once done, press CTRL + D to exit and send the mail.

  3. Sending emails to multiple recipients:
    $ mail -s “test mail” [email protected],[email protected],[email protected]
  4. Sending an email with an attachment:
    $ mail -s “File attached” [email protected] -A names.txt
  • emails from command line, mail command
  • 0 Users Found This Useful
這篇文章有幫助嗎?

相關文章

How To Install and Use Docker on Ubuntu 16.04

Introduction Docker is an application that makes it simple and easy to run application processes...

Change Main IP of the server :: Vesta Panel

If we are changing the main IP of a server installed with Vesta panel, we can use the following...

cPanel: Apache-FastCGI Data Timeout Error

If you are using a cPanel server and have FastCGI enabled in Apache, you might be facing the...

Domainkey installer in cPanel

You can use the following cPanel script to install domainkey for an account...

Email issues :: Common Troubleshooting Steps

Here I will discuss some common errors and their solution: We are using a mail relay setup for...