HITENDRA PATEL

POSTFIX SEND MAIL USING SMTP SERVER

Published 3 months ago 129 Views
image

We need to configure POSTFIX in our ubuntu system to send email using SMTP provider such as GMail, Yahoo, Mandrill, SendGrid.

To prevent application mail as SPAM, if your server’s IP has been added to a SPAM list.

In this blog, we will learn how to install and configure a POSTFIX server to send email.

Login into server using terminal.


Step 1 : Install POSTFIX

First update ubuntu with latest release of updates.

sudo apt-get update

Now, install POSTFIX

sudo apt-get install postfix

While installation, prompt will asking you about some configure to set,

First select "INTERNET SITE",

Provide fully qualified name of your domain like blogians.com


Step 2 : Configure POSTFIX main file

After installation, open following file with nano editor,

sudo nano /etc/postfix/main.cf

& find for myhostname & make sure that the domain name is configured with your fully qualified name of domain.


Step 3 : Configure SMTP

We need to configure SMTP credential to send mail with POSTFIX,  we need to make changes in password config file.

Open following file with nano editor :

sudo nano /etc/postfix/sasl/sasl_passwd

Now add SMTP credentials like host, port, username, password.

For example let's configure yahoo with this, then we need to add following line in file

[smtp.mail.yahoo.com]:587 user@yahoo.com:password

Step 4 : Create HASH of credential file

After adding credential in file, need to encrypt for database.

For that run following command :

sudo postmap /etc/postfix/sasl/sasl_passwd

Step 5 : Secure database credential file

For security we need to allow only root user to access credential file, for that run following command :

sudo chown root:root /etc/postfix/sasl/sasl_passwd /etc/postfix/sasl/sasl_passwd.db
sudo chmod 0600 /etc/postfix/sasl/sasl_passwd /etc/postfix/sasl/sasl_passwd.db

Step 6 : Configure relay server

Add or update relay host in main file of POSTFIX, open file with following command :

sudo nano /etc/postfix/main.cf

Update or add new line :

relayhost = [smtp.mail.yahoo.com]:587

Step 7 : Enable authentication for SMTP

We need to enable some authentication for SMTP server, for that add following line in main config file of POSTFIX

smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
smtp_use_tls = yes
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Save above changes & reload POSTFIX with new config.

sudo service postfix restart

Step 8 : Test Email

To check all done, we have to send a test email.

For that install following package :

sudo apt-get install mailutils

For test email with above package run following line in terminal :

echo "test body of first email" | mail -s "First email with POSTFIX" -a "From: user@yahoo.com" user@gmail.com

If all goes smooth then user@gmail.com will receive test email in inbox.

That's all done here.

A BLOG ABOUT DEVELOPMENT

Subscribe and get my latest blog post in your inbox.
image
DIGITAL OCEAN SETUP LARAVEL

Install & configure laravel project into live digital ocean server.

image
LARAVEL PUSH NOTIFICATION

Laravel push notification for devices with FCM

image
INSTALL COMPOSER ON MACOS

Install Composer on MacOS