Using Gmail SMTP to Send Emails from your Website
Create an App Password for your Google Account
In this article we’ll walk you through what you need to do to get SMTP working with Gmail in ExpressionEngine. From a high level perspective, this is what we need to do.
- Make sure 2-Step Verification is enabled for your account
- Create an App Password
If you have enabled 2-Step Verification on your Google account—which you have, right?—you will need to set up an app password that ExpressionEngine can use to authenticate. In Google, visit My Account, in the search box at the top type in “App passwords” and follow the suggested result. Here is a direct link: https://myaccount.google.com/apppasswords.
On the following screen, choose “Other” under “Select app”, and type in the name of your website or your domain. This will help you remember what you generated this app password for.
Click Generate. Google will then give you the app password that you will use in ExpressionEngine. You need to copy this password to your clipboard or keep the browser window open. When you click Done, there is no way to retrieve this app password. Don’t worry if you jumped the gun and clicked Done before copying though; just revoke the app password and make another one. The generated app password. Copy this to the clipboard before closing the window. The generated app password. Copy this to the clipboard before closing the window.
Configure Outgoing Email Settings in ExpressionEngine
In ExpressionEngine, navigate to Settings > Outgoing Email. Change the Protocol to SMTP which will open the SMTP Options. Use the following settings:
- Server address
- smtp.gmail.com
- Server port
- 465
- Username
- [email protected]
- Password
- The app password you generated earlier
- Connection type
- SSL (ssl://)
Lastly make sure your Newline character setting on this page is set to \r\n, a requirement for Google’s SMTP servers.
That’s it!
You are finished and ready to start sending emails through your Gmail account. In the Developer menu, visit Utilities, and from the Communicate utility, send yourself a test email to verify that everything is working. If you get an error message, go back through the steps starting with your Google My Account page, and verify your settings.
Caveats
Using Gmail for website-generated emails is less than ideal. There is a sending limit of 100 emails per day via SMTP (G Suite accounts with a custom domain don’t suffer this limitation). But marketing and even transactional emails coming from a Gmail account may get flagged by email servers as spam, or even as phishing emails. This affects both the deliverability of your emails as well as your account reputation. Google has a laundry list of bulk sender guidelines, and problems might result in your Gmail account being suspended.
So as a general rule, we do not recommend using Gmail SMTP for your website’s emails. It can be okay for your development environment, or if you just need something better than PHP mail()
or sendmail
for admin notifications, password reset emails, etc., and have only a handful of users. If your site has an email contact form, member registration, commenting, or discussion forums, you should use a transactional email service like:
Marketing emails are a different category from transactional emails, which are the type triggered by a user taking an action. Registering, resetting a password, being notified of subscribed comments, and so on. For marketing and bulk email, you should use a service made for that purpose like Campaign Monitor, ConstantContact, or MailChimp. Some of the transactional providers also handle marketing emails, and mention that specifically in their marketing.
If you are running a version of ExpressionEngine older than 3.5.0, this article still applies but you will need to set the newline and connection type manually in your system/user/config.php
file.
Comments 0
Be the first to comment!