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
Subject: this is the subject of the email
text text text
blah blah blah
text text
[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’ < /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.


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: