Use the mail command in RHEL6 to send external emails
First, uninstall the built-in sendmail and postfix:
Yum remove sendmail
Yum remove postfix
Then add the following lines in/etc/mail. rc:
Set from = 123456@126.com
Set smtp = smtp.126.com
Set smtp-auth-user = 123456
Set smtp-auth-password = xxxxxxx
Set smtp-auth = login
Note: from refers to the sender, smtp-auth-user and smtp-auth-password refer to the user name and password, and smtp-auth is configured as the logon mode.
Next, run the mail command to send an email. Run the following command:
Echo "Content Hello" | mail-s "Test Title"-a testfile.txt 123456@qq.com
(Echo content for the mail body,-s refers to the mail title,-a refers to the attachment, the last 123456@qq.com refers to the recipient.
For more information, see the man manual of mail.
Recommended reading:
How to send mail via command line in Linux