======Mail Servers======
=====Postfix Won't Start=====
If you have disabled IPv6, postfix won't start because it can't connect to an IPv6 interface.
/var/log/maillog will display something like this when trying to start postfix
Feb 3 14:02:13 template-tomcat postfix[2778]: fatal: parameter inet_interfaces: no local interface found for ::1
The solution is to update the postfix configuration file to only look for IPv4 interfaces.
sed -i "s/inet_protocols = all/inet_protocols = ipv4/g" /etc/postfix/main.cf
=====Configure Postfix=====
On some environments, the command to send email doesn't work because postfix doesn't know where to find an email relay. If you have an email relay available (in this example, mail.example.com), configure postfix to use it.
cat << EOF >> /etc/postfix/main.cf
myhostname = hostname.example.com
mydomain = example.com
relayhost = mail.example.com
EOF
service postfix restart
=====Send Email from Command Line=====
echo "Test Email" | mail -s "Hello world" target@example.comcat file.txt | mail -s "Hello world" target@example.commail -s "Hello world" target@example.com < file.txt
=====Send Text Email from Command Line=====
The first step is to generate a text file with the email and then pipe the file into the ssmtp command.
An example file looks like this. For this example, we will call the file email.txt
Subject: Some Subject
From: John Smith
To: Jane Doe
Hello World.
We then send the email using this commandmail target@example.com < email.txt
=====Send HTML Email from Command Line=====
The first step is to generate a text file with the email and then pipe the file into the ssmtp command.
An example file looks like this. For this example, we will call the file email.txt
Subject: Some Subject
From: John Smith
To: Jane Doe
Mime-Version: 1.0;
Content-Type: text/html; charset="ISO-8859-1";
Content-Transfer-Encoding: 7bit;
Example Title
Some Text
We then send the email using this commandmail target@example.com < email.txt
=====Install SSMTP=====
If you want to use SSMTP instead of postfix, you can install it using the following steps.
- Download and configure the [[RPM#Install_EPEL_Repository_on_CentOS_6|EPEL repository]].
- Remove sendmailyum remove sendmail
- Install ssmtpyum install ssmtp
You then configure ssmtp by editing the file /etc/ssmtp/ssmtp.conf and editing/uncommenting the following lines.
Edit the following lines:
mailhub=mail.example.com:25
Hostname=test1.example.com
FromLineOverride=YES
=====Use SSMTP=====
The simplest way to send email with SSMTP is this wayssmtp bstafford@example.com << EOF
Subject: Hello World
From: Source Name
To: Target Name
Hello World
EOF