Send Email With Google Compute Engine

Most of the people say that Google Compute Engine cant send mail. Actually it is only blocking for non google product, and common port 25 to stop spam email.

Once you integrate Google Computer Engine With Gsuite, you can send email through 25,465,587 as well.

Let see what we need to do and what we need to configure in the server.

  1. Login into your Google Admin Console
  2. Go to Apps > G Suite > Gmail > Advanced settings. (Click On the Gmail icon, so you can saw the Advanced Settings.)
  3. Scroll Down to the SMTP Relay Service > Configure
    Give it a name (Testing Google mail)
    Allowed Senders : Only registered Apps users in my domains (Thats means all the email account that i register with google gsuite will be able to be the sender in the mail server, IE:

    Tick : Only accept mail from the specified IP addresses

    ADD IP RANGE: give it a name and type in your GCE server ip address. IE:

    Tick: Require SMTP Authentication

    Tick: Require TLS encrytion

  4. Click Save

Server Setup

Now we will proceed to ubuntu server and install related software for mail send.

  1.  apt-get upgrade & apt install mailutils (Ubuntu)  yum install -y postfix cyrus-sasl-plain mailx (Centos)
  2.  hostname ( Configure your Server hostname to your domainname which is register in google gsuite IE: )
  3.  vim /etc/postfix/ add the following to end of this file.
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_sasl_security_options = noanonymous
    smtp_tls_security_level = secure
    smtp_tls_mandatory_protocols = TLSv1
    smtp_tls_mandatory_ciphers = high
    smtp_tls_secure_cert_match = nexthop
    smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
    relayhost = []:587

    For Centos User, just simply replace smtp_tls_CAfile to /etc/pki/tls/certs/ca-bundle.crt

  4. Create sasl_passwd file.
    vim sasl_passwd
    quit and save the file.
  5. postmap /etc/postfix/sasl_passwd
  6. Service postfix restart
  7. Create related gmail user in the server IE: johnson
    useradd johnson
    passwd johnson
    sudo su johnson
  8. Run command to send email.
    mail -s ” MailFROMGCE ”

    Thats all for the GCE with Gsuite mail sending, please do not hesitate to contact us if you found any problem during the setup.

    Note: Remember to enable Less Secure apps on your gmail account that you use for sending email in server. If you are using dual authentication, please generate app password and inside into sasl_passwd again, and run through the process again.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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