mail command examples

Sending mails from Linux Machine

– Have hostname entry in “/etc/hosts”, if sending mail within the system

– System should have internet connectivity, for this.

Basic Examples

# mail -s “Hello Mike” mike@centos.test

# mail mike@centos.test

# echo “test” | mail -s “Hi Mike”

# mail -s ‘Hi Mike’ < /tmp/message 


– Sending mail with attachment
    # mail -a test.txt

– Sending mail with blind carbon copy
    # mail -a test.txt -b mike@gmailer

– Sending mail with carbon copy
    # mail -a test.txt -c mike@gmailer

– To save the message after sending the mail
    # mail -F “/var/mike.mail”

– To see the headers of all the received mails
    # mail -H

– To start the mail message with the content from a file (mail message will start with the file contents)
    # mail -q /var/mike.mail

– To read mail of any user
    # mail -u mike

– To see the details of the delivery of the mail you are sending
    # mail -v 

Leave a Reply

Your email address will not be published. Required fields are marked *