Sending system emails on GCP

We have hosted our own application in GCP, and we’d like to set up system email, but seems we aren’t able to send emails through our GCP set. These would be simple system emails to users for account confirmation, password reset, etc.

Once we examined the default firewall we noted that it is saying ‘SMTP port 25 disallowed in this project’.

Do I have to use a 3rd party like SendGrid and integrate SendGrid into our GCP project? Or is there another way to solve for this?

Hi @collidescope ,

The error message you’ve encountered, which states “SMTP port 25 disallowed in this project,” signifies that GCP has implemented a security measure to restrict outbound communication on SMTP port 25 within your project. This measure is in place to mitigate the potential misuse and abuse of SMTP for spamming from GCP instances.

Here are some workarounds to send emails to your from your GCP project:

  1. Consider Using a Third-Party Email Service (Recommended): A simple solution is to use an outside email service like SendGrid, Gmail SMTP, or Mailgun. These services give you tools and email servers that let you send messages from your app without concerns about SMTP port limits.

For example, with SendGrid on GCP: You can easily include SendGrid in your GCP project. Just sign up for a SendGrid account, set up your API key or SMTP information, and then use SendGrid’s tools or SMTP server to send emails.

  1. Consider Using Different Ports: If you’d rather not use an external email service, you can attempt to adjust your email server to operate on a different SMTP port, like 587 or 465. These ports are usually not restricted by default on GCP. Keep in mind that this approach may have its drawbacks and may not be the best choice.

You can refer to this documentation regarding using standard email ports. You can also check the guides in setting up email with SendGrid, Mailgun, or Mailjet.

Google Cloud Platform (GCP) blocks outbound traffic on port 25 by default to prevent spam and abuse. This means that you cannot send emails directly from your GCP project using port 25.

There are two main ways to send emails from GCP without using port 25:

  1. Use a third-party email service such as SendGrid or Mailgun.
  2. Use the Gmail SMTP server.

Using a third-party email service

To use a third-party email service, you will need to create an account with the service and then configure your GCP project to use the service’s SMTP server.

Using the Gmail SMTP server

To use the Gmail SMTP server, you will need to create a Google Workspace account and then configure your GCP project to use the Gmail SMTP server.

Once you have configured your GCP project to use an email service, you can then send emails from your application using the email service’s API or SDK.

Which option should you choose?

The best option for you will depend on your specific needs and requirements. If you need to send a large volume of emails, or if you need to send emails with complex formatting, then using a third-party email service may be the best option. If you only need to send a small number of emails, or if you need to send emails with simple formatting, then using the Gmail SMTP server may be the best option.

Additional considerations

If you are using a third-party email service, you will need to factor in the cost of the service. Most third-party email services offer a free tier, but they may also charge for additional features or for sending a large volume of emails.

If you are using the Gmail SMTP server, you will need to make sure that your GCP project is authorized to use the server. You can do this by creating a Google Workspace account and then configuring your GCP project to use the Gmail SMTP server.

Conclusion

There are two main ways to send emails from GCP without using port 25: using a third-party email service or using the Gmail SMTP server. The best option for you will depend on your specific needs and requirements.