Configure Laravel to use Postfix via Gmail SMTP

Configure Laravel to use Postfix via Gmail SMTP

Configure Laravel to use Postfix via Gmail SMTP

Sep 21, 2015 – 2 min read


This guide will help you to configure Laravel to use Postfix via Gmail SMTP on your Ubuntu server 14.04. Once configured, all emails from your server will be sent via Gmail.

Before you begin, you need the following:

  • Ubuntu installation
  • SSH access to the server
  • Installed and configured NGINX

Postfix installation and configuration

Install all necessary packages if you don’t have Postfix installed:

During the installation select your server as “Internet Site” and for FQDN set a sub-domain of your website. For example: mail.example.com. Then open Postfix config file:

Add the following lines:

Save and Close.

We have to specify our Gmail username and password. Open or Create the following file:

and add the following line (replace USERNAME and PASSWORD with your gmail credentials):

Set the permissions below and update Postfix config to use sasl_passwd file:

Run the command below in order to validate the certificates and avoid running into an error.

Reload Postfix:

Test Postfix and Gmail SMTP

If you have configured everything correctly, the following command should generate a test email:

To confirm that, log in to your Gmail account and open “Sent Mail” folder. You should see the test email.


If you get the following error “Error: SASL authentication failed; server smtp.gmail.com” during the test, you need to unlock the Google Captcha by visiting this page – https://www.google.com/accounts/DisplayUnlockCaptcha.

Laravel Setup

Open the mail config file which is located in Laravel’s config folder:

Change the driver option to “sendmail”:

After we have configured Laravel to use Postfix, test the sending of emails via Laravel.

If you need assistance with the above or Laravel, contact me.

(The header image is taken from DigitalOcean website.)

Whenever you're ready, here's how I can help you:

1. Develop your Product: Want to start, maintain, and grow your tech business? Our team of senior software engineers at Camplight can help.

A team of +50 employee members and +1500 pre-vetted experts. We have delivered 300+ projects, handled 1200+ consultation requests, gained expertise in 4 key industries. We can manage budget scopes ranging from $1k to $800k+.

​Read more


Contact Camplight