As you know, to install a email server, you should install both Postfix and Dovecot, in this case it is quite complicated. In case you just need run sendmail function of Postfix, you should install PostFfix and config to relay to a SMTP server that you have. So in this article, I will show you steps to install and config it.
The scenario of this example as below:
You have a smtp server with configuration information as below
Firstly, install Postfix:
1 |
sudo apt-get install postfix |
Open /etc/postfix/main.cf change some parameters as below:
1 2 3 4 5 6 7 8 9 10 |
myhostname = your_domain_here #eg: example.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases mydestination = your_domain_here, localhost, localhost.localdomain relayhost = url_smtp_server:port #e.g: smtp.example.com:25 smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd smtp_sasl_security_options = noanonymous mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 mailbox_size_limit = 0 |
And create /etc/postfix/sasl_passwd file and add content below
1 |
url_smtp_server:port username:password |
Type below comand to create sasl_passwd.db:
1 |
sudo postmap /etc/postfix/sasl_passwd |
Restart Postfix:
1 |
sudo /etc/init.d/postfix restart |
Finally, test send email (make sure that you installed mail client):
1 |
echo "Test mail from postfix" | mail -s "Test Postfix" your_email@gmail.com |
You are done.
In case having errors, you can check log with command:
1 |
sudo tail -f /var/log/syslog |
And now, you can write a php script, use Swiftmailer library to test send email via transport sendmail