SMTP Hosting: Setup and Usage Guide
SMTP (Simple Mail Transfer Protocol) is the standard protocol used to send emails over the internet. If you need to set up an SMTP hosting server for sending emails, this guide will walk you through everything from selecting a provider to configuring your SMTP server.
For closely related mail-stack topics, see Email Hosting Script — Self-Hosted Setup, MX Hosting — Complete Guide, Gmail 550-5.7.1, and Email Rate Limited.
Choosing an SMTP Hosting Provider
You can either:
- Use a third-party SMTP provider (easier, recommended for businesses).
- Set up your own SMTP server (for full control).
Popular Third-Party SMTP Providers
| Provider | SMTP Server Address | Free Tier? |
|---|---|---|
| Google SMTP (Gmail) | smtp.gmail.com | Limited |
| SendGrid | smtp.sendgrid.net | 100 emails/day |
| Mailgun | smtp.mailgun.org | 5,000 emails/month |
| Amazon SES | Varies by region | Pay-as-you-go |
| Postmark | smtp.postmarkapp.com | Pay-as-you-go |
If you choose a third-party service, you will get SMTP login credentials from them.
Setting Up Your Own SMTP Server (Linux)
To run your own SMTP hosting, you need to install an SMTP server like Postfix, Exim, or Sendmail.
Install and Configure Postfix (Recommended)
Postfix is a popular SMTP server for sending emails.
Install Postfix
sudo apt update && sudo apt install postfix -y # Ubuntu/Debian
sudo yum install postfix -y # CentOS/RHEL
Configure Postfix
During installation, you will be prompted to choose a type of mail configuration. Select "Internet Site" and set:
- System mail name: yourdomain.com
- SMTP relay: None (if sending directly)
You can manually edit the configuration:
sudo nano /etc/postfix/main.cf
Add or modify:
myhostname = mail.yourdomain.com
mydomain = yourdomain.com
myorigin = $mydomain
inet_interfaces = all
mynetworks = 127.0.0.0/8
relay_domains =
home_mailbox = Maildir/
Save and exit.
Restart Postfix
sudo systemctl restart postfix
sudo systemctl enable postfix
Test SMTP Server
echo "Test email from my SMTP server" | mail -s "SMTP Test" recipient@example.com
Install and Configure Exim (Alternative)
For CentOS/RHEL users, Exim is a great alternative to Postfix.
Install Exim
sudo yum install exim -y
Enable Exim
sudo systemctl start exim
sudo systemctl enable exim
Configure Exim
Edit the configuration file:
sudo nano /etc/exim/exim.conf
Modify:
domainlist local_domains = @ : yourdomain.com
Save and restart:
sudo systemctl restart exim
SMTP Authentication Setup
To prevent unauthorized usage, enable SMTP authentication.
Install SASL for Authentication
sudo apt install libsasl2-modules sasl2-bin -y # Ubuntu/Debian
sudo yum install cyrus-sasl -y # CentOS/RHEL
Configure SASL for Postfix
Edit:
sudo nano /etc/postfix/sasl/smtpd.conf
Add:
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
Restart SASL:
sudo systemctl restart saslauthd
sudo systemctl enable saslauthd
Restart Postfix:
sudo systemctl restart postfix
Setting Up SMTP with an Email Client
Once your SMTP server is running, you can configure an email client (e.g., Outlook, Thunderbird, Gmail) to send emails.
SMTP Settings for Email Clients
| Setting | Value |
|---|---|
| SMTP Server | mail.yourdomain.com |
| SMTP Port | 587 (STARTTLS), 465 (SSL), or 25 (Unencrypted) |
| Username | your_email@yourdomain.com |
| Password | Your SMTP password |
| Encryption | TLS or SSL |
Example: Configuring Outlook
- Open Outlook.
- Go to File > Account Settings > Add Account.
- Select Manual setup.
- Choose IMAP or POP.
- Enter:
- Incoming mail server: mail.yourdomain.com
- Outgoing mail server (SMTP): mail.yourdomain.com
- Username: Your full email address.
- Password: Your SMTP password.
- Click More Settings > Outgoing Server, check "My SMTP server requires authentication".
- Click Advanced and set:
- SMTP Port: 587 (TLS) or 465 (SSL).
Testing SMTP Configuration
Use Telnet
telnet mail.yourdomain.com 25
Type:
EHLO yourdomain.com
MAIL FROM: <you@yourdomain.com>
RCPT TO: <recipient@example.com>
DATA
Subject: Test Email
This is a test email.
.
QUIT
Use Swaks (SMTP Debugging Tool)
sudo apt install swaks -y
swaks --to recipient@example.com --server mail.yourdomain.com --auth LOGIN --auth-user your_email@yourdomain.com --auth-password yourpassword
SMTP Logs & Troubleshooting
Check Postfix Logs
sudo tail -f /var/log/mail.log
Check Exim Logs
sudo tail -f /var/log/exim_mainlog
Common Errors & Fixes
| Error | Fix |
|---|---|
| "Relay access denied" | Ensure SMTP authentication is enabled. |
| "Connection timed out" | Check if port 25, 465, or 587 is open in the firewall. |
| "Too many connections" | Set SMTP rate limits in /etc/postfix/main.cf. |
Secure Your SMTP Server
- Enable SPF, DKIM, and DMARC
- SPF Record (DNS TXT):
v=spf1 mx -all - DKIM Signing (Postfix):
- DMARC Policy (DNS TXT):
- Limit SMTP Relay to Specific IPs
Add to main.cf:
smtpd_client_restrictions = permit_mynetworks, reject_unknown_client - Enable SSL/TLS Encryption
Install Let's Encrypt SSL for secure email transmission:
sudo apt install certbot -y sudo certbot certonly --standalone -d mail.yourdomain.com
sudo apt install opendkim opendkim-tools -y
v=DMARC1; p=none; rua=mailto:postmaster@yourdomain.com
- If you need quick SMTP hosting > Use SendGrid, Mailgun, or Gmail SMTP.
- If you want full control > Set up Postfix or Exim on your server.
- Secure your SMTP > Enable authentication, SPF, DKIM, and SSL.


