How to configure google mail with digital ocean

To configure Google Mail (Gmail) with DigitalOcean, you'll need to set up a few things:

Step 1: Create a Google Cloud account and enable the Gmail API

  1. Go to the Google Cloud Console and create a new project.
  2. Click on "APIs & Services" and search for "Gmail API".
  3. Click on the "Gmail API" result and click on the "Enable" button.
  4. Create credentials for your project by clicking on "Create Credentials" and selecting "OAuth client ID".
  5. Choose "Other" as the application type and enter a name for your client ID.
  6. Click on "Create" and copy the client ID and client secret.

Step 2: Create a DigitalOcean droplet and install Postfix

  1. Create a new DigitalOcean droplet and choose a distribution (e.g., Ubuntu).

  2. Connect to your droplet using SSH and install Postfix:

    sudo apt-get update
    sudo apt-get install postfix

    Step 3: Configure Postfix to use Gmail as the mail server

  3. Edit the Postfix configuration file:

    sudo nano /etc/postfix/main.cf
  4. Add the following lines to the end of the file:

    mydestination = example.com
    myhostname = example.com
    myorigin = /etc/mailname
    relayhost = [smtp.gmail.com]:587
    smtp_use_tls = yes
    smtp_tls_security_level = encrypt

    Replace example.com with your domain name.

Step 4: Generate a password for Postfix

  1. Generate a password for Postfix:
    sudo dpkg-reconfigure postfix

    Follow the prompts to set up the Postfix password.

Step 5: Configure Gmail to allow less secure apps

  1. Go to the Google Account settings page and click on "Security".
  2. Scroll down to the "Less secure app access" section and toggle the switch to "On".

Step 6: Test your setup

  1. Send an email from your DigitalOcean droplet to a Gmail address:
    echo "Test email" | mail -s "Test email" [email protected]

    If everything is set up correctly, you should receive the email in your Gmail inbox.

Step 7: Configure your domain to use Gmail as the mail server

  1. Go to the DigitalOcean DNS settings page and create a new record:
    • Type: MX
    • Name: @ (or your domain name)
    • Value: 1 aspmx.l.google.com
    • TTL: 3600
  2. Create another record:
    • Type: MX
    • Name: @ (or your domain name)
    • Value: 5 alt1.aspmx.l.google.com
    • TTL: 3600
  3. Create another record:
    • Type: MX
    • Name: @ (or your domain name)
    • Value: 5 alt2.aspmx.l.google.com
    • TTL: 3600
  4. Create a TXT record:
    • Type: TXT
    • Name: @ (or your domain name)
    • Value: "v=spf1 include:_spf.google.com ~all"
    • TTL: 3600

This should configure your domain to use Gmail as the mail server. You can test your setup by sending an email from your domain to a Gmail address.