Call Us! 1-800-383-5193
Call Us! 1-800-383-5193
Call Us! 1-800-383-5193

Need Help?

Emergency Response Time custom

Our experts have had an average response time of 11.06 minutes in March 2021 to fix urgent issues.

We will keep your servers stable, secure and fast at all times for one fixed price.

Configure Mailgun in Google Cloud – How to do

by | Jul 4, 2021

Wondering how to Configure Mailgun in Google Cloud? We can help you!

Google Cloud works with Mailgun to provide an email service that has a programmatic API, log retention, email personalization, analytics, and email validation.

Here at Bobcares, we often handle requests from our customers to configure Mailgun on their GCP as a part of our Server Management Services.

Today we will see how our Support Engineers do this for our customers.

How to configure Mailgun in Google Cloud

Now we will see the steps that our Support Engineers follow for this setup.

Prerequisites for configuring Mailgun:

Following are the prerequisites for this setup:

1. First we need to create a new Mailgun account.

2. Then get the credentials such as username and password from the Mailgun control panel, under the Domains section.

3. And configure the firewall rules to allow outgoing traffic on TCP port 2525.

Configuring Mailgun as a mail relay with Postfix

Configuring Mailgun as a mail relay allows the Postfix mail transfer agent to forward emails destined for remote delivery.

  1. First, we must instance using SSH.
    gcloud compute ssh [INSTANCE_NAME]
  2. To become a superuser we can use the following command:
    $ sudo su -
  3. Then set a safe umask using the following command:
    # umask 077
  4. After that, we can install the Postfix Mail Transport Agent.
    # apt update && apt -y install postfix libsasl2-modules
  5. When prompted, select the Local Only configuration and accept the default choices for domain names.
  6. To Modify the Postfix configuration options we must open the file:
    # vi /etc/postfix/
  7. And comment out the following lines if they exist:
    # default_transport = error
    # relay_transport = error
  8. Then we can add the Mailgun SMTP service by inserting the following line to the end of the file.
    relayhost = []:2525

    Note: We must use port 2525 here since port 25 is not allowed on Compute Engine.

  9. To enforce SSL/TLS support and configure SMTP authentication for these requests, we must add the following lines to the end of the file:
    smtp_tls_security_level = encrypt 
    smtp_sasl_auth_enable = yes 
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd 
    smtp_sasl_security_options = noanonymous
  10. After making the changes we can save the changes and close the file.
  11. For generating the SASL password map we can do the following:
    1. Create a new password file that is ready for standard input.
      # cat > /etc/postfix/sasl_passwd << EOF
    2. And enter the service details, replacing YOUR_SMTP_LOGIN and YOUR_SMTP_PASSWORD with our credentials.
    3. Now, close and save the file by typing the delimiter, EOF.
       > EOF
  12. Use the postmap utility to generate a .db file:
    postmap /etc/postfix/sasl_passwd
  13. Verify that there is a .db file using the following command:
    ls -l /etc/postfix/sasl_passwd*
    -rw------- 1 root root    ...  /etc/postfix/sasl_passwd
    -rw------- 1 root root    ...  /etc/postfix/sasl_passwd.db
  14. Remove the file containing the credentials because it is no longer needed:
    rm /etc/postfix/sasl_passwd
  15. Set the permissions on the .db file and verify that the other file was removed:
    # chmod 600 /etc/postfix/sasl_passwd.db
    # ls -la /etc/postfix/sasl_passwd.db
    -rw------- 1 root root 12288 Aug 31 18:51 /etc/postfix/sasl_passwd.db
  16. After that we can reload our configuration to load the modified parameters:
    /etc/init.d/postfix restart
  17. Install the mailutils or mailx package:
    apt -y install mailutils
  18. Send a test email:
    echo 'message' | mail -s subject
  19. Finally, we can  check the system logs for a status line containing status and the successful server response code (250):
     tail -n 5 /var/log/syslog

[Need assistance? We can help you]


To conclude, we saw the steps that our Support Techs follow to Configure Mailgun in Google Cloud for our customers.


Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.


var google_conversion_label = "owonCMyG5nEQ0aD71QM";


Submit a Comment

Your email address will not be published. Required fields are marked *

Privacy Preference Center


Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]


Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid


Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie


These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.