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
- Go to the Google Cloud Console and create a new project.
- Click on "APIs & Services" and search for "Gmail API".
- Click on the "Gmail API" result and click on the "Enable" button.
- Create credentials for your project by clicking on "Create Credentials" and selecting "OAuth client ID".
- Choose "Other" as the application type and enter a name for your client ID.
- Click on "Create" and copy the client ID and client secret.
Step 2: Create a DigitalOcean droplet and install Postfix
-
Create a new DigitalOcean droplet and choose a distribution (e.g., Ubuntu).
-
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
-
Edit the Postfix configuration file:
sudo nano /etc/postfix/main.cf
-
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
- 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
- Go to the Google Account settings page and click on "Security".
- Scroll down to the "Less secure app access" section and toggle the switch to "On".
Step 6: Test your setup
- 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
- 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
- Create another record:
- Type: MX
- Name: @ (or your domain name)
- Value: 5 alt1.aspmx.l.google.com
- TTL: 3600
- Create another record:
- Type: MX
- Name: @ (or your domain name)
- Value: 5 alt2.aspmx.l.google.com
- TTL: 3600
- 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.