Configure SMTP Server using Google Service
It is possible to set up an SMTP email server with the domain mail.introvesia.com
that relays emails through Google's SMTP servers (like Gmail or Google Workspace). This is commonly done using Postfix (or another MTA) as a relay host configured to use Google's SMTP servers. Here's how you can achieve this:
Step-by-Step Guide
1. Configure Your DNS
Set up the following DNS records for mail.introvesia.com
:
-
MX Record:
introvesia.com. IN MX 10 mail.introvesia.com.
-
A Record (for the mail server):
mail.introvesia.com. IN A <Your Server IP>
-
SPF Record (to allow Google servers to send mail for your domain):
introvesia.com. IN TXT "v=spf1 include:_spf.google.com ~all"
-
DKIM and DMARC Records:
- Set these up if you're using Google Workspace or want to improve email deliverability. Google provides DKIM keys in the Google Admin console.
2. Install Postfix
Install Postfix on your server if it’s not already installed:
sudo apt update
sudo apt install postfix -y
Choose the "Internet Site" configuration during installation and set mail.introvesia.com
as the system's mail name.
3. Configure Postfix as a Relay
Edit the Postfix configuration file (/etc/postfix/main.cf
) to relay emails through Google's SMTP servers:
sudo nano /etc/postfix/main.cf
Add or modify the following settings:
# Basic Settings
myhostname = mail.introvesia.com
myorigin = /etc/mailname
relayhost = [smtp.gmail.com]:587
# TLS Settings
smtp_use_tls = yes
smtp_tls_security_level = encrypt
smtp_tls_note_starttls_offer = yes
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
# Authentication Settings
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_tls_security_options = noanonymous
4. Set Up Authentication
Create a credentials file for Google's SMTP authentication:
sudo nano /etc/postfix/sasl_passwd
Add the following line, replacing <your-email>
and <your-password>
with your Gmail/Google Workspace credentials:
[smtp.gmail.com]:587 <your-email>@gmail.com:<your-password>
Secure the file:
sudo chmod 600 /etc/postfix/sasl_passwd
Generate a Postfix database map file:
sudo postmap /etc/postfix/sasl_passwd
5. Restart Postfix
Restart Postfix to apply the changes:
sudo systemctl restart postfix
6. Test Sending an Email
Test your configuration by sending an email:
echo "This is a test email" | mail -s "Test Email" [email protected]
Check /var/log/mail.log
for details if the email is not sent successfully.
Considerations
-
Google SMTP Limits:
- Gmail accounts have a daily sending limit (e.g., 500 emails per day). For higher limits, use Google Workspace.
- If you encounter authentication errors, you might need to enable "Less Secure App Access" for your Google account or use an App Password for added security.
-
Use of Custom Domain (Optional): If you use Google Workspace, you can set up your custom domain (
mail.introvesia.com
) for Gmail directly in the Google Admin console. -
SPF, DKIM, and DMARC: Properly configure these DNS records for better email deliverability and security.
-
Firewall Rules: Open the necessary ports (25, 587, 465) for SMTP traffic on your server.
By following these steps, you can configure mail.introvesia.com
to use Google's SMTP servers as a relay for sending emails while maintaining your domain branding.
No Comments