How to send email from linux console

Sending an email from console is an easy procedure that comes in handy. I use it a lot, mainly when I setup a new mail server to send test email or when I want to send the contents of a big configuration file.

To install the mail command in red-hat based distributions, issue

yum install mailx

To install the mail command in debian based distributions, issue

apt-get install bsd-mailx

To send an email from console

  1. Issue the mail command followed by the recipient email address press enter
  2. Enter the desired subject press enter
  3. Enter the desired main body of the email press enter
  4. type “.” a dot press enter
  5. If you want to cc it to somebody else enter the email address, else leave it blankĀ  press enter

[root@host ~]# mail user@domain.com
Subject: this is the subject of the email
THIS IS THE MAIN TEXT OF THE EMAIL
text text text
blah blah blah
text text
.
Cc: user2@domain.com
[root@host ~]#

If you want to send the contents of a file, issue the mail command again in the following form

[root@host ~]# mail -s ‘subject’ user@domain.com < /path/to/file/filename

  1. I have installed bsd-mailx, and still can’t sending email to my Gmail account.

    Please let me know step by step installing bsd-mailx + configuration on ubuntu.

    Thanks

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trackbacks and Pingbacks: