Sourav Chatterjee
Sourav Chatterjee

Reputation: 179

Send emails from GCP compute instance using smtp-relay of GMAIL

I am trying to send mail from a compute instance using Gmail's smptp relay and I have enabled smtp-relay through my GSuite account and have also configured POSTFIX in my compute instance and as per mail.log file the mail has been delivered but it is not appearing in my Gmail box. Could you please let me know what is being missed?

Here is the log for the same.

enter image description here

Upvotes: 3

Views: 5700

Answers (1)

Serhii
Serhii

Reputation: 4461

At first, have a look at the Firewall rules overview where at section Always blocked traffic you can find that:

Google Cloud always blocks the traffic that is described in the following table. Your firewall rules cannot be used to allow any of this traffic:

always_blocked_traffic

So, you should follow documentation Choosing an email service to use:

To use a G Suite domain: Follow the instructions for SMTP relay service settings in the G Suite documentation. SMTP relaying through G Suite is only allowed through ports 465 or 587.Port 25 is not supported through G Suite.

and use ports 465 or 587 to connect to G Suite.

Also have a look at this guide SMTP relay: Route outgoing non-Gmail messages through Google:

  1. In the Allowed senders section, select the users who are allowed to send messages through the SMTP relay service:

    • Only registered Apps users in my domain—The sender must be a registered user in one of your domains.

    • Only addresses in my domains—The sender doesn't have to be a recognized G Suite user, but must be in one of your registered domains. This can be useful when you have third-party or custom applications that need to send messages.

    • Any addresses (not recommended)—The sender address can be anything, even an address outside of your domain.

Important: The Any addresses option makes you more vulnerable to abuse, either through malware on your user’s machines or by misconfiguration of your SMTP infrastructure. Therefore, we don't recommend this option.

and check who is allowed to send emails, then follow next step:

  1. In the Authentication section, check one or both boxes to set an authentication method:

    • Only accept mail from the specified IP addresses—The system only accepts mail sent from these IP addresses as coming from your domains.
    • Require SMTP Authentication—Enforces the use of SMTP authentication to identify the sending domain. Using this option requires your clients to connect via TLS.

and check if you use whitelisted your instances.

In addition, this example could be useful to check your steps.

In case if you still have an issue, check possible alternatives SendGrid:

This tutorial shows how to use SendGrid to send email from an app running on a Compute Engine instance. SendGrid is a third-party email service that offers Compute Engine users a free trial with 12,000 transactional emails free each month.

or Mailgun, or Mailjet. If they work for you, but you still need G Suite you can contact G Suite Support. It they don't work for you also - you should check you Postfix configuration first.

Upvotes: 4

Related Questions