Setting up email on Google Cloud Platform is a straightforward process. You can create a new email address using the Google Cloud Console, which is a web-based interface for managing your Google Cloud resources.
To start, you'll need to create a new project in the Google Cloud Console, if you haven't already. This will give you access to the Google Cloud Platform services, including Gmail.
Google Cloud Platform offers a range of email services, including Gmail, which is a popular choice for businesses and individuals alike. Gmail is known for its reliability, security, and ease of use.
With Gmail, you can set up custom email addresses and domains, which is perfect for businesses that want to create a professional email address. You can also use Gmail's advanced features, such as email filtering and labels, to help you manage your email more efficiently.
Setting Up Gmail API
To set up the Gmail API, start by navigating to your Google Cloud Console sidebar and clicking on APIs & Services » Library. If you don't see APIs & Services, scroll down and click on MORE PRODUCTS.
Enabling the Gmail API is a straightforward process. Simply look under Category and click on Google Workspace, or enter “Gmail API” in the search bar. On the Gmail API page, click on the blue ENABLE button.
After enabling the Gmail API, you should be redirected to the Gmail API Overview page. Click on the CREATE CREDENTIALS button to proceed.
Google will ask a few questions to determine the Credential Type you need. From the Select an API dropdown, choose Gmail API. Make sure you have the Gmail API enabled for your account if you don't see an option for it.
Next, under What data will you be accessing?, select the User data option. Then click the NEXT button to proceed.
Configuring Gmail Permissions
Enabling the Gmail API is a straightforward process. You can do this by going to your Google Cloud Console sidebar and clicking on APIs & Services » Library.
To find the Gmail API, look under Category and click on Google Workspace, or enter “Gmail API” in the search bar. This will take you to the Gmail API page where you can click on the blue ENABLE button.
If you’re not using Google Workspace, you won’t see the MAKE EXTERNAL option, and instead, you’ll need to publish your Google app. To do so, go to APIs & Services » OAuth consent screen and click the PUBLISH APP button.
Note that for more information on Gmail API scopes, please see Google’s developer documentation. This will provide you with a deeper understanding of the permissions required for your app.
To view the Client ID and Client Secret, click the pencil icon on the Credentials page. You can then copy both of these values into the corresponding fields in your WP Mail SMTP settings.
Be very careful not to copy any extra text or spaces with your Client ID or Client Secret, as this will result in an error in the next step.
Managing Gmail Users
If you're using Gmail and want to manage users, you'll need to consider whether you're using Google Workspace or not.
If you're not using Google Workspace, you won't see the MAKE EXTERNAL option.
To publish your Google app, go to APIs & Services » OAuth consent screen and click the PUBLISH APP button to update your app status.
Gmail Users
If you're a Gmail user, you won't see the MAKE EXTERNAL option.
This is because you're not using Google Workspace, which is a requirement for accessing external email addresses.
To publish your Google app, go to APIs & Services » OAuth consent screen.
Under Publishing status, you'll see the app status is set to Testing, and you'll need to click the PUBLISH APP button to update your app status.
Once confirmation is complete, your app's Publishing status will be updated to In production.
Mailbox Watch Request
To create a Mailbox Watch Request, you need an access token generated by the Generate Gmail Token step. This token is required to create a watch for the Pub/Sub topic.
You can use the Gmail Watch Topic step to create a watch, which will determine which mailbox will be monitored for changes and which changes will become push notifications on your webhook.
To use the Gmail Watch Topic step, you'll need to provide a Gmail access token, user email, label IDs, and topic name. The topic name is copied from GCP.
To monitor the INBOX label, for example, you'll need to provide the INBOX label ID. You can create a watch request using a pre-defined topic template to skip this step and the next one.
A watch will expire after 7 days, so it's a good idea to create a scheduled workflow to renew the watch automatically.
Backup Connection
Setting up a Backup Connection is optional but recommended to improve email deliverability.
A Backup Connection serves as a backup in case your Primary Connection fails. This means your emails will still be delivered even if your main connection is down.
Configuring a Backup Connection is not required to complete your Google Workspace / Gmail mailer setup. However, it's a good idea to have one in place for added security.
You can route your emails through a specific additional connection based on rules or conditions, but that's a topic for another tutorial.
Introduction and Setup
Setting up your own email server on Google Cloud Platform (GCP) can be a game-changer for anyone looking for a free private email server.
You'll need to start by setting up a GCP VM instance, which can be done in the free tier, meaning you won't incur any costs, excluding the cost of a domain name.
To receive emails, you'll need to set up firewall rules, which will be covered in the first part of this series.
For a brief rundown, the software you'll be installing and running on your VM includes Postfix, Dovecot, MariaDB, Rspamd, Sieve, Postfixadmin, Roundcube, Nginx, and PHP-FPM.
Here's a quick rundown of the software you'll be using:
- Postfix: to send and receive email
- Dovecot: for IMAP access to your mailbox
- MariaDB: as your database for storing users and other necessary data
- Rspamd: to detect spam
- Sieve: (a scripting language) to move spam to the junk folder
- Postfixadmin: as an admin web interface for easy management
- Roundcube: as your webmail client
- Nginx and PHP-FPM: to serve Roundcube and Postfixadmin via the web
GCP blocks all outgoing traffic on port 25, used by SMTP for email delivery, so you'll need to set up a mail relay using a service like Mailgun, which will be covered in this series.
If you're familiar with setting up a personal email server or this list of software, you might notice that ClamAV (anti-virus) is omitted from the list, which is because the free tier of GCP doesn't offer a VM with enough RAM to effectively run it.
Trigger Events
Trigger events are the starting point for many Google Cloud Platform email automations. They can be triggered by various events, such as new emails arriving in a mailbox.
To extract information from a trigger event, you'll need to decode the trigger event data. This can be done using the Decode base64 step with the input: {{ $.event.message.data }}.
Once decoded, you can parse the event using the Add data to context step with the input: {{ $.decode_gmail_notification.result }}. This will make the event data readable and usable in your automation.
You can then use the Generate Gmail Token step to generate an access token to use in the Gmail steps. This token will allow you to interact with the Gmail API.
The List Mailbox Changes History step can be used to retrieve all mailbox changes that have occurred since the trigger event. This can be useful for keeping track of changes to the mailbox.
Here are the steps involved in processing a trigger event:
- Decode the trigger event data
- Parse the decoded event
- Generate a Gmail token
- List mailbox changes history
The step output will contain the email in a readable format, including sender, date and time when the email was received, subject, receiver, email body, and more.
Sending Email
Sending Email with Google Cloud Platform Email is a seamless process. You can send emails using the Gmail API, which allows you to access Gmail's functionality programmatically.
To send emails, you'll need to enable the Gmail API in the Google Cloud Console and create credentials for your project. This will give you a client ID and client secret that you can use to authenticate your API requests.
You can then use the Gmail API to send emails, including setting the recipient's email address, subject, and body. The API also allows you to attach files and track email status.
From
From the basics of email sending, it's clear that the "From" field is crucial in establishing your identity as the sender. The "From" field is where you enter your email address, which is the address that the recipient will see when they receive your email.
Your email address is a unique identifier that helps the recipient respond to your email and also helps email providers filter out spam. I've seen this firsthand when I've accidentally used a generic email address and had trouble getting responses from recipients.
The "From" field also allows you to include your name, which can add a personal touch to your email. However, be sure to keep it professional and relevant to your email content.
Mailer
To set up your mailer, you should see a new section appear titled Google / Gmail with more authorization options.
You have two ways to configure the Google Workspace / Gmail mailer: Using the One-Click Setup or manually creating a custom Google app. The One-Click Setup is a straightforward approach that doesn't require creating a custom Google app.
However, if you're using the Lite version of WP Mail SMTP or need to generate the information for the Client ID and Client Secret fields, you'll need to create a web application using your Google account.
Frequently Asked Questions
What is the email format for Google Cloud Platform?
Google Cloud Platform's email format is typically [email protected], used by 53% of contacts. Other formats may vary, such as [email protected] and [email protected].
Sources
- https://wpmailsmtp.com/docs/how-to-set-up-the-gmail-mailer-in-wp-mail-smtp/
- https://help.drata.com/en/articles/4663373-gcp-google-cloud-platform-connection
- https://help.deepsecurity.trendmicro.com/20_0/on-premise/gcp-account-create.html
- https://medium.com/geekculture/how-to-host-a-personal-email-server-on-google-cloud-for-free-part-i-8124d65d1d25
- https://kb.torq.io/en/articles/9138324-receive-gmail-push-notifications-using-google-cloud-pub-sub
Featured Images: pexels.com