Setting up your own SMTP Server (Simple Mail Transfer Protocol) on a VPS from VPS-Hosting.org allows you to send and receive emails efficiently while maintaining full control over your email infrastructure. Whether for transactional emails, newsletters, or general business communication, an SMTP server ensures better email deliverability and lower costs compared to third-party services.
This guide will walk you through the step-by-step process to set up an SMTP server on your VPS.
Follow the steps below to Setup SMTP Server
Step 1: Choose a VPS from VPS-Hosting.org
Recommended VPS Specifications
- OS: Ubuntu 22.04 / Debian 12 / CentOS 8
- RAM: Minimum 2GB (4GB recommended for high-volume email sending)
- CPU: 2 vCPUs or higher
- Storage: 20GB SSD or more
- Dedicated IP: Required to prevent blacklisting
For this buy VPS 8 Core 8GB RAM 200gb SSD from VPS-Hosting.org and ensure it comes with a dedicated IP address for better email deliverability.
Step 2: Update & Configure Your VPS
Once your VPS is set up, access it via SSH:
ssh root@your-vps-ip
Update the system packages:
sudo apt update && sudo apt upgrade -y # Ubuntu/Debian
sudo yum update -y # CentOS
Step 3: Install Postfix (SMTP Server)
Postfix is a popular open-source SMTP server for sending emails.
Install Postfix
sudo apt install postfix -y # Ubuntu/Debian
sudo yum install postfix -y # CentOS
During installation, select:
- General type of mail configuration: Internet Site
- System mail name: Your domain (e.g.,
mail.yourdomain.com
)
Start and enable Postfix:
sudo systemctl enable postfix
sudo systemctl start postfix
Step 4: Configure Postfix
Edit the Postfix main configuration file:
sudo nano /etc/postfix/main.cf
Modify/add the following lines:
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
relayhost =
mynetworks = 127.0.0.0/8, [YOUR VPS IP]/32
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP $mail_name
smtpd_tls_cert_file=/etc/letsencrypt/live/mail.yourdomain.com/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/mail.yourdomain.com/privkey.pem
smtpd_tls_security_level=may
Save and exit (CTRL+X
, then Y
, then Enter
). Restart Postfix:
sudo systemctl restart postfix
Step 5: Set Up SPF, DKIM, and DMARC for Better Email Deliverability
SPF Record
Add the following TXT record in your domain’s DNS settings:
v=spf1 mx a ip4:YOUR_VPS_IP -all
DKIM Setup
Install OpenDKIM:
sudo apt install opendkim opendkim-tools -y
Configure DKIM:
sudo nano /etc/opendkim.conf
Add:
Domain yourdomain.com
KeyFile /etc/opendkim/keys/yourdomain.com/default.private
Selector default
Socket inet:8891@localhost
Restart OpenDKIM:
sudo systemctl restart opendkim
DMARC Record
Add this TXT record in your DNS settings:
v=DMARC1; p=none; rua=mailto:postmaster@yourdomain.com
Step 6: Test Your SMTP Server
Use telnet
to verify if your SMTP server is working:
telnet mail.yourdomain.com 25
If connected, type:
EHLO mail.yourdomain.com
You should see a response starting with 250-
.
For sending emails, you can also use:
echo "Test Email" | mail -s "Subject" recipient@example.com
Step 7: Secure Your SMTP Server
Enable TLS Encryption
Install Let’s Encrypt SSL:
sudo apt install certbot -y
sudo certbot certonly --standalone -d mail.yourdomain.com
Enable TLS in Postfix:
sudo postconf -e 'smtpd_tls_cert_file=/etc/letsencrypt/live/mail.yourdomain.com/fullchain.pem'
sudo postconf -e 'smtpd_tls_key_file=/etc/letsencrypt/live/mail.yourdomain.com/privkey.pem'
Restart Postfix:
sudo systemctl restart postfix
Limit Open Relay to Prevent Spam
Edit /etc/postfix/main.cf
and add:
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
Restart Postfix:
sudo systemctl restart postfix
Step 8: Monitor and Maintain Your SMTP Server
Check Mail Logs
tail -f /var/log/mail.log
Test Email Sending
Use an external email client (Thunderbird, Outlook) to send emails via your SMTP server.
Conclusion
Setting up an SMTP server on a VPS from VPS-Hosting.org provides full control over email delivery. By implementing SPF, DKIM, DMARC, and TLS encryption, you enhance security and reduce the chances of emails landing in spam. With proper monitoring and configuration, you can build a reliable self-hosted email solution.
FAQs
Q1: Can I use my SMTP server for bulk emailing?
Usually many vps provider donot allow bulk mailing. Usually they block port 25. Please ask support to open port 25. And if they allow Yes, but ensure your VPS can handle high-volume emails, and follow email-sending best practices to avoid blacklisting.
Q2: Why are my emails going to spam?
- Ensure SPF, DKIM, and DMARC are correctly configured.
- Warm up your IP by sending small email batches first.
Q3: Can I integrate my SMTP server with WordPress or applications?
Yes! Use the SMTP details in plugins like WP Mail SMTP to send emails from your website.