In this KB
- How to Configure Gmail SMTP
This KB explains how you can configure Google’s free SMTP relay service on your web server for reliable delivery of outgoing emails.
It is a good alternative as compared to PHP mail function. You can use this type of SMTP service for receiving customer queries via your application’s contact form, password reset emails, order confirmation etc. However, this comes with a limit for sending email i.e. 500 emails per day or 500 recipients in a single email per day.
So if you want to send transactional and marketing emails (in volumes), we recommend you to configure a third party email delivery service such as Elastic Email add-on (paid).
Step 1: Allow Access to Google Account
Before using Gmail SMTP, you need to authorize your server to access your Google account.
Click here, log into your Gmail account, then click Continue.
Note: You should use your main Google account for achieving this purpose. If you have merged accounts from google you will receive an authentication error.
This will enable your account access for your new device (web server). You can move to Step 2 if your Google account is setup without two-factor authentication.
If you have enabled two-factor authentication on your Google account, you would need to generate application specific password (select “Other/Custom name” for device type and give it a name such as “DO – Production Server”). Note down the application password as it will be required in the next step.
Now, open the link again and click Continue.
Step 2: Configure Gmail on the SMTP Add-on
Enter the Gmail details inside SMTP addon (to activate SMTP addon).
- Select Other /Custom SMTP from the drop down menu
- Enter smtp.gmail.com as your host
- Use port 587
- Enter your Gmail login username firstname.lastname@example.org
- Enter your Gmail password OR Application password (if using 2 Factor Authentication)
Click Save to finalize the settings on the server.
That’s it. Your Gmail email service has been configured on your server for outgoing transactional emails.
Step 3: Test SMTP Functionality
Once the settings are updated you can test it by sending mail through SSH.
Once logged in via ssh, use the following command to send mail for testing:
mail -s “subject” email@example.com
Write your content and press enter
Use ctrl + d to send the mail.
You can whether it is successful or not by checking if you have received the email. If the email does not get delivered you can use the mailq command to check for errors.
If mail queue is empty, then the mail is sent successfully from your server.
If the mail queue displays an error (e.g: SASL authentication failed), then you need to return to Step 1 and authenticate access to your account from Gmail.
Note: It is important to note that the From header of the emails sent via Gmail SMTP will use your default Gmail address. The email recipient will see the Gmail address or any email address that you have associated with the Gmail account settings to be used as sender, instead of the sender email address that you have defined in your application.
Frequently Asked Questions:
Q: Can I use Port 25?
A: We do not have any restriction from our end but upstream providers such as Vultr and Google keep this port blocked for security reasons. Therefore it is recommended that you use port 587.
Q: Does my server support SSL port?
A: Postfix (mail transfer agent) on the server prefers STARTTLS (port submission/587) over port 465. So it is recommended to use port number 587 (TLS).
Q: How can I configure email service on my web application?
A: You can use the default settings (PHP mail scripts) to send mail from your web applications. You can also use SMTP plugin or extension on application level as well.
Q: Should I choose Gmail SMTP or Elastic Email Add-on?
A: As explained, Gmail SMTP comes with a limitation for outgoing emails (i.e. 500 emails per day or 500 recipients in a single email per day). Whereas with Elastic Email, there is no as such limitations. You can send as many emails as you want as per your requirements and selected package plan.