If you’re one of those people who hate relying on third-party email providers to send emails, setting up your own SMTP server could be the solution you’re looking for. Third-party email service providers can be expensive and may not offer you the kind of control you would like to have over the specifics of the email infrastructure.
This guide will walk you through the steps you need to follow you seat up a local SMTP server for yourself on multiple operating systems, along with the pros and cons of having one.
What is an SMTP server?
An SMTP server (Simple Mail Transfer Protocol server) is an important component of email communication that manages the process of sending, receiving, and relaying emails. It allows the emails to be sent from the sender's email client to the recipient's email server.
You can think of the SMTP server as your city’s post office. When you send a letter, it first goes to your local post office; then it travels to your recipient’s post office, who then delivers it to the right address.
Pros and cons of running your own SMTP server
Before you invest time and resources to build an SMTP server, it’s important to think about the long-term advantages and disadvantages. Let’s explore them:
Pros
Highly customizable: Setting up your SMTP server allows you to intricately customize your messaging preferences to suit your specific needs, such as sending limits, tracking pixels, and automatic responses.
Predictable costs: With an SMTP server, your costs are typically more predictable. Rather than being surprised by unexpected increases in pricing due to sending more emails, you can plan for consistent costs related to your server’s infrastructure.
Better control: Being able to customize everything, you have full control over email limits and policies. This is something that you have no control over in third party email providers.
Cons
Need heavy maintenance: Running your own SMTP server requires ongoing maintenance, such as software updates, security checks, and hardware management. This can be time-consuming and resource-intensive.
Complex process: Custom servers need permissions from ISPs, get their port enabled and have a static IP allocated in some cases. This makes the entire process pretty complex.
Struggle with security: To secure an SMTP server, you need to additionally install an SSL certificate and enable a firewall. Third-party solutions generally come with strong security measures that prevent any unauthorized breaches without you having to take any extra steps.
How to set up an SMTP server
The process of setting up an SMTP server can be quite comprehensive and varies based on the operating system. Below, we’re discussing how you can set up a local SMTP server on different operating systems. It’s important to note that this is a basic set up and is usually used for testing purposes.
1. Setting up an SMTP server in Linux
Setting up an email server on Linux usually involves using Mail Transfer Agents (MTAs) software like Exim, Postfix, or Sendmail.
Since Exim and Sendmail have less secure architecture and are not beginner-friendly, we’ll be using Postfix.
Installation
- Start by opening up a Linux terminal.
- Make sure your system is up-to-date with the latest APT packages by typing the command below. The response will show you the number of packages or applications that have updates available.
sudo apt update
- Next, check if Postfix is installed on your computer by typing the following command:
sudo apt-cache policy postfix
If the response says installed: (none)
, it means that the application isn’t installed.
- In that case, you can easily install it with the following command:
sudo apt install postfix -y
- During the installation process, choose the Internet Site option for the mail setup.
- Now, enter your website’s fully qualified domain name (FQDN). For example, it could be something like mail.example.com.
Configuration
- Once Postfix is installed, it is time to set up your Postfix service. First, enable it to start automatically during system boot by giving the following command.
sudo systemctl enable postfix
- Next, start the software by typing:
sudo systemctl start postfix
It won’t give you any response after this, but you can then check the status using the following command:
sudo systemctl status postfix
It’ll show you the status as ‘Active’ if it’s running. Also, you won’t be able to give any other command in the status display. Press q to exit this status display.
- Before configuring your SMTP server, back up your main.cf file, as you will be editing it a lot.
sudo cp /etc/postfix/main.cf /etc/postfix/main.cf.backup
- Next, run the following command to open the main.cf file:
sudo nano /etc/postfix/main.cf
- In this file, you’ll need to make a couple of changes:
- First, find the line that says
inet_interfaces = all
and change it to:
inet_interfaces = loopback-only
- Locate the
mydestination
line and edit it to include all your domain names. It should look something like this:
mydestination = $myhostname, localhost.$example.com, $example.com
Once you've finished editing, press Ctrl + X to exit Nano. It will prompt you to save the changes; simply press Y to confirm.
To apply the changes, return to the main terminal window and restart Postfix by typing:
sudo systemctl restart postfix
- Then check whether Postfix is running or not post-restarting by typing:
sudo systemctl status postfix
Testing
- Now that everything’s set up, let’s make sure it’s working. First, install Telnet, a command-line tool used for connecting to remote servers. You can do that using the following command:
sudo apt-get install telnet
- Open the Terminal and run this command to connect to your remote SMTP server:
telnet localhost 25
If the connection is successful, it’ll the response will say Connected to localhost
- Finally, send a test email by typing the following commands— one at a time. Press Enter after each one to get a response for your command. Note that 250 stands for confirmation or Ok.
So, this is what the commands would look like:
HELO example.com
250 mail.example.com
MAIL FROM:<sender@example.com>
250 message ID OK
RCPT TO:<recipient@example.com>
250 message ID OK
DATA
354 End data with <CR><LF>.<CR><LF>
Tip: This means the server is ready to accept the message content.
Subject: Test Email
This is the body of the first email to my test server.
.
250 OK, queued as 12345.
QUIT
221 message id Bye
When you run the above commands and see the same output as mentioned, it indicates your SMTP server is up and running on the Linux system.
2. Setting up an SMTP server in Windows
For setting up an SMTP server on Windows, you’ll need to install a third-party tool like Amazon SES, MailEnable, or hMailServer. In this tutorial, however, we’ll be using hMailServer, as it’s free and easy to set up.
Installation
Download the hMailServer software from the official website.
Follow the onscreen steps to install your software.
Keep in mind:
On the Select Components window, select the Full Installation option and make sure both Server and Admin are ticked.
On the Select Database Server window, opt for the built-in database engine option.
In the hMail Server Security window, pick a strong but easy-to-remember password.
Configuration
Launch the hMailServer Administrator. On your first run, you will be asked to enter the password you set during installation.
Click on the Connect button on the top right to access the hMailServer Administrator console.
Click on Domains from the sidebar on the left. This will open a modal on the right.
Select the Add Domain button to create a new domain. Here, enter your domain name and click Save. You can now see your domain listed on the left sidebar.
Under your Domain thread on the left, click on Accounts. Here, provide your email address and create a new account.
Tip: Your email address format should be something like this: user@example.com
Tap Save to finish setting up the account.
Now, go to Settings > Protocols > SMTP from the left sidebar. Uncheck POP3 and IMAP and click Save.
Go back to the Settings thread and select the logging option. Here, check the Enable box at the top, followed by selecting Application, SMTP, and TCP/IP. Then click Save.
Now, go back to the Settings thread, but this time, select Advanced > IP Ranges. Here, remove the internet range.
Then, click on MY COMPUTER range and uncheck the boxes for POP3, IMAP, anti-spam, anti-virus, and external to external email addresses and tap Save.
The next step is to figure out how you want your emails to be sent. You have two options.
- Activate hMailServer as a relay server:
Go to Settings > Protocols > SMTP from the left-hand side.
Go to the Delivery of Email tab.
Fill out the SMTP relayer portion with details like remote host name, TCP/IP port, authentication, and security settings.
- Setup hMailServer as a mail server:
Go to Settings > Protocols > SMTP and open the Delivery of Email tab.
Leave the SMTP relayer section blank.
At the top, fill in the Local hostname text field with your IP reverse lookup hostname.
Tip: You can use an IP reverse lookup tool to find the accurate hostname.
Important Note: With this setup, emails go directly to the recipient instead of passing through your email server. As a result, no copy is saved on the server and has a higher chance of being flagged as spam. Set up an SPF record to help prevent this.
- Restart your hMailServer by going to the Windows Services. You can find it easily by pressing Windows+R, typing
services.msc
, and hitting Enter.
Testing
Open your email client (e.g., Outlook) and create a new account. All you need to do is enter your email address, password, and the incoming and outgoing mail server details.
Type an email and try to send it.
If the test email doesn’t send successfully, review your SMTP settings. You can use the hMailServer built-in diagnostic tool to do this:
Go to hMailServer Administrator > Utilities > Diagnostics.
Choose your domain.
Click Start. The diagnostic tool will automatically check for issues like DNS or mail ports and provide recommendations for any necessary fixes.
3. Setting up an SMTP server in MacOS
Postfix is usually pre-installed on macOS, but if you need to ensure it is installed, you can use the built-in Homebrew package manager.
Installation
Launch the Terminal app from the Applications > Utilities folder.
Run the following command to check if Postfix is already installed:
postfix -v
Tip: If installed, this command will display your postfix version information.
- If it’s not installed, you can install it using Homebrew with the command:
brew install Postfix
Configuration
- Once Postfix is installed, open the Postfix configuration file using a text editor like Nano:
sudo nano /etc/postfix/main.cf
- Modify the following parameters in the main.cf file:
myhostname: Enter the name of your computer (e.g., myhostname = your.hostname.com).
mydomain: Set your domain name (e.g., mydomain = yourdomain.com).
mydestination: Set the local domains Postfix will handle (e.g., mydestination = $myhostname, localhost.$mydomain, localhost).
relayhost: relayhost = [smtp.yourprovider.com]:587
For enabling SASL authentication:
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
To enable encryption:
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/cert.pem
After making these changes, press CTRL+X, then press Y to confirm, and hit Enter to save.
To secure your SMTP server, create a SASL file for storing your credentials. Run the following command to create the password file:
sudo nano /etc/postfix/sasl_passwd
Tip: Add your SMTP server credentials in this format:
[smtp.yourprovider.com]:587 username@gmail.com:yourpassword
- You must secure the password file by setting the file permissions feature. Use the following command for that:
sudo chmod 600 /etc/postfix/sasl_passwd
- Postfix needs a hash database to read the password file. Create it by running:
sudo postmap /etc/postfix/sasl_passwd
- Finally, restart Postfix to apply your changes by typing:
sudo Postfix reload
Testing
- To check if everything is working, send a test email from the Terminal. Use this command:
echo “Test email body” | mail -s
“Test Email Subject”
recipient@example.com
Check your inbox to ensure the message was delivered successfully.
If not delivered, check your email logs (located in /var/log/mail.log) for any issues or errors.
tail -f /var/log/mail.log
What's a better alternative?
Setting up your own SMTP can take a lot of time and effort, particularly if you’re not a techie. It might even require you to hire an expert to do this for you. There are also multiple aspects to look into and multiple things to tweak and fix once in a while.
A much simpler option is to go with a third-party email service provider or email marketing platform that takes care of all these requirements and provides additional benefits. You can choose Mailmodo as a low-cost, highly functional alternative to this.
Start sending emails with Mailmodo today
Final thoughts
Whether you are a Mac, Windows, or Linux user, now you have all the instructions to set up your own SMTP server.
While having your dedicated SMTP server makes it easy to send dozens of emails, an email marketing tool like Mailmodo can readily set your email-sending infrastructure, minimise deliverability issues, and protect your address against those tricky email-based attacks.
So, give it a try today.