Many faced the problem of sending messages from the server of the bash / perl / python / php / etc …
In fact it is quite simple.
Enough to put sendmail.
yum install sendmail sendmail-cf -y
chkconfig –level 345 sendmail on
/etc/init.d/sendmail start
Starting sendmail: [OK]
Starting sm-client: [OK]
In principle, you can already send mail, but the default configuration specified that you are sending mail from the host localhost.localdomain
The next section is made in view of the fact that your hostname is set up correctly in the system.
Customize this system variable in CentOS, you can file / etc / sysconfig / network
Check what you have now hostname, if not strange, you can command hostname =))
So make changes to the configuration of sendmail
sed -i -e “s / ^ LOCAL_DOMAIN. * $ / LOCAL_DOMAIN (\` $ {HOSTNAME} \ ‘) dnl / g “/etc/mail/sendmail.mc
make -C / etc / mail
/etc/init.d/sendmail restart
Shutting down sm-client: [OK]
Shutting down sendmail: [OK]
Starting sendmail: [OK]
Starting sm-client: [OK]
It is time to test what we’ve got.
respectively substitute your email address instead of [email protected]
echo “The test body” | mail -s “The test subject” [email protected]
Everything can go in the mail, and check their spam Since this letter is likely to be in it. Since the A record and PTR record DNS, the same as your external IP. By the way, this design can work through NAT.
Note:
Gmail.com in this letter is likely to fall into the spam box and to Mail.ru did not come because the administration is trying to protect their Mail.ru hamsters from all kinds of spam.