Post Date: November 16, 2020
Last Updated: November 17, 2026
Introduction
Email communication is essential for websites, applications, and business operations. Linux servers commonly send automated emails for password resets, contact forms, application notifications, system alerts, and other important activities.
Google Workspace provides an SMTP relay service that allows websites, applications, and mail servers to send outgoing emails through Google’s mail infrastructure. By configuring Google Workspace SMTP relay with Exim, you can improve email delivery reliability and securely route outgoing emails from your Linux server.
In this guide, we will explain how to configure the Google Workspace SMTP relay service with Exim on a Linux server. We will cover Google Admin Console settings, SMTP relay authentication, TLS encryption, firewall configuration, Exim configuration, and email testing.
Prerequisites
Before configuring Google Workspace SMTP relay, ensure that you have:
- An active Google Workspace account.
- Access to the Google Workspace Admin Console.
- A Linux server with Exim installed.
- A static public IP address for IP-based authentication.
- Root or sudo access to the Linux server.
- Access to configure firewall rules.
- A verified domain configured in Google Workspace.
Step 1: Configure Google Workspace SMTP Relay Service
First, configure the SMTP relay service in the Google Workspace Admin Console.
1. Sign in to Google Admin Console
Open the Google Admin Console using your administrator account:

2. Navigate to Gmail Advanced Settings
- Navigate to Apps.
- Select Google Workspace.
- Select Gmail.
- Open Routing.
- Locate the SMTP relay service setting.

3. Configure SMTP Relay Service
Under the SMTP relay service section:
- Click Configure or edit the existing SMTP relay setting.
- Enter a suitable description for the relay configuration.
- Configure the allowed senders.
- Select the required authentication method.
4. Configure Allowed Senders
Under the Allowed senders section, choose the appropriate option based on your requirements:
- Only registered Apps users in my domains: Allows registered Google Workspace users to send emails.
- Only addresses in my domains: Allows email addresses belonging to your verified domains.
- Any addresses: Allows any sender address. This option is not recommended unless specifically required.
For most business environments, use a domain-restricted sender option to prevent unauthorized email sending.
5. Configure Authentication
Under the Authentication section, configure the authentication method.
Google Workspace supports the following authentication options:
Option A: Only accept mail from specified IP addresses
This option allows Google Workspace to identify your server using its public IP address.
- Enable Only accept mail from the specified IP addresses.
- Click Add IP range.
- Enter a description for the server.
- Enter your server’s public IP address.
- Enable the IP address entry.
Example:
123.123.123.123
Replace the example IP address with your actual server’s public IP address.
For security reasons, authorize only the required IP addresses.
Option B: Require SMTP Authentication
You can also enable SMTP authentication if your server or application requires it.
When SMTP authentication is enabled, configure the appropriate authentication credentials on your SMTP client and ensure that the connection uses TLS.
For this guide, we will use IP-based authentication with a static public IP address.
6. Enable TLS Encryption
Under the Encryption section:
- Enable Require TLS encryption.
- This ensures that communication between your server and Google’s SMTP relay is encrypted.
- Click Save.
Finally, save the SMTP relay configuration in the Google Admin Console.
Step 2: Configure Firewall Rules to Allow Outbound SMTP Traffic
Your Linux server must be able to establish an outbound connection to Google’s SMTP relay server.
In this guide, we will use TCP port 587 with STARTTLS encryption.
Configure Google Cloud Firewall
If your Linux server is hosted on Google Cloud Platform, follow these steps:
- Log in to the Google Cloud Console.
- Navigate to VPC Network → Firewall.
- Click Create Firewall Rule.
- Enter a suitable name for the firewall rule.
- Select the network hosting your VM instance.
- Under Direction of traffic, select Egress.
- Select the appropriate target instances or network tags.
- Under Destination filter, configure the required destination range.
- Under Protocols and ports, select Specified protocols and ports.
- Select TCP and enter
587. - Click Create.
Verify that your firewall configuration allows outbound SMTP connections.
If you are using another cloud provider or a Linux firewall, ensure that outbound TCP port 587 is permitted.
Step 3: Check and Install Exim on the Linux Server
Connect to your Linux server through SSH.
Check whether Exim is installed:
which exim
Check the installed Exim version:
exim -bV
If Exim is not installed, install it according to your Linux distribution.
For Ubuntu or Debian:
apt update apt install exim4 -y
Check the Exim service status:
systemctl status exim4
On distributions using the exim service name, use:
systemctl status exim
Step 4: Configure Exim to Use Google Workspace SMTP Relay
After confirming that Exim is installed, configure it to route outgoing emails through Google Workspace SMTP relay.
The configuration file location may vary depending on your Linux distribution.
For systems using a traditional Exim configuration file, the configuration is commonly located at:
/etc/exim/exim.conf
1. Back Up the Existing Exim Configuration
Before making any changes, create a backup:
cp /etc/exim/exim.conf /etc/exim/exim.conf.bak
2. Configure the SMTP Router
Open the Exim configuration file:
nano /etc/exim/exim.conf
Search for:
begin routers
Add the following router configuration under this section:
send_via_google: driver = manualroute domains = ! +local_domains transport = google_smtp route_list = * smtp-relay.gmail.com
Make sure this router is placed before the general-purpose router that handles outgoing DNS routing, so messages intended for external domains are routed through Google SMTP relay.
Router Configuration Explanation
send_via_google: Defines the router name.driver = manualroute: Routes outgoing emails through a specified SMTP server.domains = ! +local_domains: Applies the router to non-local destination domains.transport = google_smtp: Specifies the SMTP transport.route_list: Routes outgoing emails through Google’s SMTP relay server.
3. Configure the SMTP Transport
Search for:
begin transports
Add the following configuration:
google_smtp: driver = smtp port = 587 hosts_require_tls = *
Transport Configuration Explanation
driver = smtp: Uses Exim’s SMTP transport.port = 587: Connects to Google’s SMTP relay using port 587.hosts_require_tls = *: Requires TLS encryption for the SMTP connection.
4. Configure SMTP Authentication
For this configuration, we are using IP-based authentication. Therefore, you do not need to configure a Google username and password in Exim.
Google Workspace identifies the server using the public IP address authorized in the SMTP relay settings.
If you choose SMTP authentication instead, configure the appropriate supported authentication method and securely store the credentials.
Avoid storing plain-text passwords in publicly readable configuration files.
5. Restart Exim
After completing the configuration, validate the Exim configuration:
exim -bV
Restart Exim:
systemctl restart exim4
If your distribution uses the exim service name:
systemctl restart exim
Check the service status:
systemctl status exim4
Step 5: Test the Google Workspace SMTP Relay Connection
After configuring Exim, verify that your Linux server can establish a secure connection to Google’s SMTP relay.
Run:
openssl s_client -starttls smtp -connect smtp-relay.gmail.com:587 -crlf
If the connection is successful, you should see the SMTP server response and TLS certificate information.
You can also test network connectivity using:
nc -vz smtp-relay.gmail.com 587
A successful connection indicates that the server can reach the SMTP relay on the configured port.
Step 6: Send a Test Email
Once the SMTP relay connection is working, send a test email from your Linux server.
Run:
echo "This is a test email from the Google Workspace SMTP relay configuration." | mail -s "SMTP Relay Test" recipient@example.com
Replace recipient@example.com with the actual recipient email address.
If the mail command is not installed, install the required mail utility package for your Linux distribution.
Check the Exim mail queue:
exim -bp
Check Exim logs:
For Ubuntu or Debian:
tail -f /var/log/exim4/mainlog
For other distributions, the log may be located at:
tail -f /var/log/exim/mainlog
If the message is accepted and delivered successfully, your Google Workspace SMTP relay configuration is working.
Step 7: Troubleshoot Common SMTP Relay Issues
If your emails are not being delivered, check the following common issues.
1. Relay Access Denied
Possible reason: The server’s public IP address is not registered in Google Workspace SMTP relay settings.
Solution:
- Verify the server’s public IP address.
- Check the authorized IP address in Google Admin Console.
- Confirm that the sending domain is configured correctly.
- Verify that the envelope sender and sender domain are permitted.
2. Connection Timed Out
Possible reason: Outbound SMTP traffic is blocked by the server firewall, cloud firewall, or hosting provider.
Solution:
- Verify outbound TCP port 587.
- Check cloud firewall egress rules.
- Confirm that your hosting provider allows SMTP connections.
- Test connectivity using
ncor OpenSSL.
3. TLS Connection Failed
Possible reason: TLS configuration or certificate validation issues.
Solution:
- Check that OpenSSL is installed.
- Verify the server’s system date and time.
- Confirm that TLS is enabled in the Exim transport.
- Test the connection using OpenSSL.
4. Emails Are Not Appearing in the Recipient’s Inbox
Possible reason: The email may have been rejected, filtered as spam, or delayed.
Solution:
- Check Exim mail logs.
- Verify SPF, DKIM, and DMARC DNS records.
- Review Google Workspace Email Log Search.
- Check the recipient’s spam folder.
- Verify that the sending IP and domain have a good reputation.
5. SMTP Authentication or IP Validation Error
Possible reason: The server is sending through an IP address that is not authorized in Google Workspace SMTP relay settings.
Solution:
- Verify the server’s public IP address.
- Update the SMTP relay IP allowlist.
- Check the sender domain.
- Verify the SMTP relay authentication settings.
Best Practices for Google Workspace SMTP Relay
Follow these security and email delivery best practices:
- Use a static public IP address for IP-based authentication.
- Enable TLS encryption for outgoing SMTP connections.
- Avoid storing account passwords in plain-text configuration files.
- Restrict SMTP relay access to authorized IP addresses.
- Configure SPF, DKIM, and DMARC for your sending domain.
- Monitor Exim mail logs regularly.
- Keep Exim and the Linux operating system updated.
- Follow Google Workspace SMTP relay sending limits and policies.
- Use a valid sender address belonging to your authorized domain.
- Review email delivery and spam reports regularly.
Conclusion
Configuring Google Workspace SMTP relay with Exim provides a reliable way to send outgoing emails from Linux servers, websites, and applications. By configuring the SMTP relay service in the Google Admin Console, authorizing your server’s public IP address, enabling TLS encryption, and updating the Exim router and transport settings, you can establish a secure email delivery solution.
It is also important to configure SPF, DKIM, and DMARC records, monitor mail server logs, and regularly review SMTP relay permissions to maintain email security and improve email deliverability.
If you need professional assistance with Google Workspace SMTP relay configuration, Exim mail server setup, email troubleshooting, or Linux server administration, Pheonix Solutions provides reliable infrastructure and server management services to help your business maintain secure and efficient email communication.
Frequently Asked Questions (FAQs)
1. What is Google Workspace SMTP relay service?
Google Workspace SMTP relay service allows websites, applications, and mail servers to send outgoing emails through Google’s SMTP infrastructure. It supports IP-based authentication and SMTP authentication, depending on the configured settings.
2. Which SMTP server and port are used for Google Workspace SMTP relay?
The Google Workspace SMTP relay hostname is smtp-relay.gmail.com. Port 587 is commonly used with STARTTLS encryption. Other supported connection options depend on Google’s SMTP relay configuration and your server’s requirements.
3. Can I configure Google Workspace SMTP relay with Exim on Linux?
Yes. You can configure Exim to route outgoing emails through Google Workspace SMTP relay. You need to configure the Exim router, SMTP transport, TLS encryption, and the appropriate authentication method.
Related Articles
Setup Postfix with Mailgun for Reliable Email Delivery on Ubuntu
How to Fix Postfix Delayed Mail Delivery: A Complete Troubleshooting Guide
Need Help Integrating SendGrid with Postfix?
Looking to configure SendGrid SMTP relay, troubleshoot email delivery issues, or manage outgoing email services on your Linux server?
Pheonix Solutions provides Linux server administration, email server configuration, SMTP integration, cloud hosting, server security, and infrastructure management services.
Our team can help you configure Postfix, integrate SendGrid SMTP relay, troubleshoot email authentication failures, resolve email delivery issues, configure secure mail services, and maintain your Linux server environment efficiently.
Get in touch with our team to discuss your email server integration and Linux server management requirements.
