Create and read emails using the MAIL command in Linux

Home > Search > Linux commands
  by

The mail command can be used to send an email. Use apt-get or yum to install the mail command.

~]# yum install mailx

 

In this example, an email is sent to john.doe@example.com. This assumes there is a user account for john.doe on the example.com email server. In this example, after typing "Hello John", press Ctrl + D to send the email.

[root@server1 ~]# mail john.doe@example.com
Subject: Example subject
Hello John
EOT

 


Subject

The -s option can be used to include the subject in the command line, so that you are not prompted for the subject.

[root@server1 ~]# mail -s "Example subject" john.doe@example.com

 


Message Body

Echo can be used to add a message in the command line, so that you are not prompted for the message.

[root@server1 ~]# echo "Example message" | mail john.doe@example.com

 


Carbon copy

The -c option can be used to carbon copy.

[root@server1 ~]# mail -c jane.doe@example.com john.doe@example.com

 

The -b option can be used to blind carbon copy.

[root@server1 ~]# mail -b jane.doe@example.com john.doe@example.com

 


Verbose

The -v (verbose) option can be used to diplay more information.

[root@server1 ~]# mail -v john.doe@example.com
250-mail.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
Hello user1
EOT

 


Mail log

View the mailog to ensure the email was delivered.

[root@server1 ~]# tail /var/log/maillog
. . . 
Mar 27 21:23:16 mail1 postfix/local[2079]: 94D795845: to=<user1@localhost>, orig_to=<user1@localhost>, relay=local, delay=0.05, delays=0.03/0.01/0/0, dsn=2.0.0, status=sent (delivered to Maildir)
. . .

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter in the box below so that we can be sure you are a human.




Comments