Using OAuth 2.0 with Google Workspace/Gmail for sending outbound emails
Sending emails from devices and application servers has recently become challenging because many SMTP servers require
you to use OAuth 2.0, but legacy devices and applications cannot use this mechanism. You can use Xeams to bridge
this gap. This page discusses configuring your devices/application servers to send emails to Xeams, which will then
deliver those messages through your Google Workspace account.
Use Case
Consider the following scenario:
- You have an application server or a device, such as a printer, that generates emails. Assume the sender of this
email is accounting@yourcompany.com, and the recipient is client@yahoo.com.
- You're using Google Workspace to host your domain.
- This app runs on a network that is either behind a dynamic IP address or has outbound port 25 blocked, forcing
you to send your emails through Google's SMTP server.
Solution
Use the following solution to route such emails:
- Install Xeams inside the same LAN where your application server/device is located.
- Configure your application server/devices to send outbound emails to Xeams. This can be done without authentication
since both Xeams and the application server are inside a trusted network.
- Xeams can authenticate with Google's servers using OAuth 2.0 to deliver emails.
The following diagram shows the flow.
Prerequisites
You must complete the following tasks before proceeding:
Device/App Server Configuration
Most devices and application servers accept values for SMTP servers when they need to send outbound emails. If your device
and Xeams are running on the same network, you can use the local IP address or hostname of the machine running Xeams for the SMTP server.
If needed, you can create users in Xeams and then specify those users for SMTP Authentication. Alternatively, you can allow certain
IP addresses in Xeams to relay.
Xeams Configuration
You must configure the Smart Host (under Server Configuration) to route messages through Google Workspace. During
configuration, you will be prompted for three parameters:
- User ID
- Client ID
- Client Secret
The remainder of this document talks about steps you need to take to get the values for these parameters.
Creating Project in Google
The User ID above refers to any valid user in your company, with an email that is hosted on Google Workspace. Values for the
remaining two configuration parameters mentioned above are obtained by creating a project in Google Cloud.
The following section discusses step-by-step instructions on how to achieve this goal.
Step 1 - Create a project
Log in to your account on
https://console.cloud.google.com and
create a new project as shown in the image below.
Give your project a new, such as
Xeams Smart Host, as show below.
Note
You will need the Project Creator role for you account in order to create a project. Go to IAM & Admin/AIM
and give your account the Project Creator role.
Step 4 - Assigning Credentials
After creating the OAuth credentials, you will see a screen similar to the following image:
Copy the values for Client ID, and Client secret. Paste them into Xeams interface.
Enter an email address for a valid user in your company. Refer to the screenshot below for a sample.
Step 5 - Sign In
After clicking the
Save button, you will be redirected to Google's login page. Finally, you should see a screen confirming
your consent.
You will be ready to send emails to Google's
SMTP server from Xeams' smart host once this login is complete.
Step 6 - Setting up Delegated Users
Notice that the User ID in the previous steps is set to John Doe's email. This means that John Doe must be the sender of
every outbound email. If Jane Doe tries to send an email through this Smart Host, Google will replace sender's address to
match John.
No further action is required if you are okay with this logic. To change this behavior, you must perform two additional steps:
- Configure the email settings in Google to allow Delegates.
Refer to this page for instructions.
- Tell Jane Doe to add John as a delegate using the instructions
on this page.