How to Set Up SMTP Server in 2025

Mashkoor Alam
ByMashkoor Alam

11 mins read

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

  1. Start by opening up a Linux terminal.

https://lh7-rt.googleusercontent.com/docsz/AD_4nXdmyC0aJMF2az04b9-VFgOQXEiHrb06BlOG8XhVqwwAedGGF3bsSDDr79CIWsPyYxSsMnxIj5ZpLQY7yUe7iFZOKyaT2FpEhB33eauhwvpYjW1JouPRtj4gIqGnoUkuXhbB9sXeLw?key=yQysIUu6sgCj8ZPEcLc7vE6F

  1. 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

https://lh7-rt.googleusercontent.com/docsz/AD_4nXdkJzSlnTXw-u1HFdmJmxyCSPLpEPfBf7EnsYggagYRbvfOv-Gq44qz-yPPpJ7wnLociNYZtRsD-L6jflZEoIPj388yfdJ9YYiQZK2JlYtuUfUTE1qDET20PohZObxoEmOiFVPFaQ?key=yQysIUu6sgCj8ZPEcLc7vE6F

  1. Next, check if Postfix is installed on your computer by typing the following command:

sudo apt-cache policy postfix https://lh7-rt.googleusercontent.com/docsz/AD_4nXcr25uE_nrjQ--X35w3kjW0fTdFhwKgMotbY2h77dp_q0oMu5P6aOA_0v3u5_4_Dc-X4KU1faGAReABCN1jytgkrUXE-7azAJ5aN2xcTG3YQwhJ6kcWY9glxsnQqwlq4QlzvGHK?key=yQysIUu6sgCj8ZPEcLc7vE6F

If the response says installed: (none), it means that the application isn’t installed.

  1. In that case, you can easily install it with the following command:

sudo apt install postfix -y

  1. During the installation process, choose the Internet Site option for the mail setup.

https://lh7-rt.googleusercontent.com/docsz/AD_4nXfV4Uw6JzBXMZMS0iAP04Gp_fYz4mH7Kfxw3qDsxeGccQq9Ul3EjbIZfdzFYdnzd6L6ieamabvwKc-gp32Bmu429wlmZXgBeGfq0SvJHQICPuCeXk5WuFGdEDE_eM0-OQ3FdRk-7Q?key=yQysIUu6sgCj8ZPEcLc7vE6F

https://lh7-rt.googleusercontent.com/docsz/AD_4nXduT2b0QI2S35xRz2K8pJgSvaPynAmDc6aMXPbXTWJFJ0DbKMmYFkdQDkKQlvdpxxPjy6BmswXbWrPxCxtQgYXl4B8KsVbel8TJxzGq090C76cD9ykjQsn2bkVwqfXsRmZ-ncoUzg?key=yQysIUu6sgCj8ZPEcLc7vE6F

  1. Now, enter your website’s fully qualified domain name (FQDN). For example, it could be something like mail.example.com.

https://lh7-rt.googleusercontent.com/docsz/AD_4nXdBnMl2YENxuf54taFNoKB_k1ssNFJTQtpQoGtcZVLtEfELYMFBRdqOj_tmyxjhj1IfR7qW5LoiXnv_EV2SZcO5rbJ3mwQ0BTXqMFxdYhasGlC6Q2eCMD9jMm5Eo3Dwk0134gLRwQ?key=yQysIUu6sgCj8ZPEcLc7vE6F https://lh7-rt.googleusercontent.com/docsz/AD_4nXfZurJMz5OcxtWrSBqfHytpY_W_O6mchT_JjfsQhlydZ_LDRtHE2bfef4qlcIgimZzhJjt9Du2-q_9hgTCKMCQJHjXHNDCPGjseojNYtePyXFJ1UXj52LxwiZ3Z0PoDWs7QJ_FMww?key=yQysIUu6sgCj8ZPEcLc7vE6F

Configuration

  1. 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

https://lh7-rt.googleusercontent.com/docsz/AD_4nXdtMOQgRi_e3INsrMkv4cIw7GT7eXUIb0pZVP-fus4_ejlthLLXCau7VaCHqW3shG6b8AJg9rlEYYnIt-4_ux-Syn0-OobrAdRgKGLXsTMoHEIoQa_l6OdHgwOJsMH52SGBxuyw?key=yQysIUu6sgCj8ZPEcLc7vE6F

  1. Next, start the software by typing:

sudo systemctl start postfix

https://lh7-rt.googleusercontent.com/docsz/AD_4nXcpek82uW0skgnG0V5Ga-ABNIyPFeSdQJlXJaKMbre2nty1sVpKwR366pNIYsTsQBzx_-ALkV9QTHruRvjnHPNLRomUlz9A4l3YUz7xIxVJHCLSAWzYkNEjeK49BC72_V_bUUnbHw?key=yQysIUu6sgCj8ZPEcLc7vE6F

It won’t give you any response after this, but you can then check the status using the following command:

sudo systemctl status postfix

https://lh7-rt.googleusercontent.com/docsz/AD_4nXflYoLoHFLOHqD3XN9znwgxiVXhlPD06a6qRnWGaHuD_jFJxkI3-tfQ8aguTpFnZTxQRGOskubng25YYRr75edd__nz8IJQLcVUwxAlKINKkE0CBZ7dnUbX2XLQfskJuWfMcTUrmw?key=yQysIUu6sgCj8ZPEcLc7vE6F

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.

  1. 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

https://lh7-rt.googleusercontent.com/docsz/AD_4nXeTvrYDdsRBycIkwqEQEXV94-nerkkZwMaN8tgWyC2I77o2g9zFMEvWkzXk7j6w4DXgBBPJiWQClGCdjqbTbZ8B_zOEFM902nQeK8v6-ZIqNZL-F3NkBnETLMGDyYllq3NbAyzZlg?key=yQysIUu6sgCj8ZPEcLc7vE6F

  1. Next, run the following command to open the main.cf file:

sudo nano /etc/postfix/main.cf

  1. 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

https://lh7-rt.googleusercontent.com/docsz/AD_4nXe_btc_FrhIcBKUz6IdPzdGOvRVkmTvdFrwPDz7h61_tlGRi25taW2AabA6lswFkZdwawMWnuSz7DbdsiA_HRozE3NB77BRW3BulPk_N313h1kM-h7YqB3UQ7oixXwCOe7pK7yW?key=yQysIUu6sgCj8ZPEcLc7vE6F

https://lh7-rt.googleusercontent.com/docsz/AD_4nXcnd3H6Mnsu4Nm_TBWFTrFserBjcHu5e3L2nLVyg-DwiXAl6E9l5efucNnKXUKP_6AMEQqLdVGCHDMhG4TeXvBH4781CdOrMjV7mepLXUVu-ItvzI5SEI0S0Da6DXePOO9qK-Q1_Q?key=yQysIUu6sgCj8ZPEcLc7vE6F

  • 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

  1. Once you've finished editing, press Ctrl + X to exit Nano. It will prompt you to save the changes; simply press Y to confirm.

  2. To apply the changes, return to the main terminal window and restart Postfix by typing:

sudo systemctl restart postfix

  1. Then check whether Postfix is running or not post-restarting by typing:

sudo systemctl status postfix

https://lh7-rt.googleusercontent.com/docsz/AD_4nXfor1BnugSBnLuLHnK9OCPzCiuh4wmGyYcNF4gTNH9C0sYTOKAqUmS921V8Z_0hrcJ1Zhux_StMw8ugOd-Y4mZJCuKXVBmoScswG994cLMVsTAE4FD4klYtb4Zwo1MKSGm0C_rn?key=yQysIUu6sgCj8ZPEcLc7vE6F

Testing

  1. 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

https://lh7-rt.googleusercontent.com/docsz/AD_4nXd8GNAlmy68aMtTR1B6QSspGAofkdNndBTDCCGvXOUzJY-PNhK1fk3Guq32z-fdlJb6AbbFLzGBu_dg4fj9tLQJ-yCc7-YsjDhb49NZSsVgn3Q3uqH05g4hD4IsFZyEd8TpU-l85A?key=yQysIUu6sgCj8ZPEcLc7vE6F

  1. 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

https://lh7-rt.googleusercontent.com/docsz/AD_4nXexmKKrlEDvhNALbsjr-9h-S2xxPLKkdi2CqrRu-M5HXdDOb1t2ZpwuCkfAUDFIN5eH5rL_0bTPceQOMrtJ_GHYnbr6-9LbO9dP4Qbl0JhOlI2KDqDW1QtxCdxnLA28PVcSyTSQ?key=yQysIUu6sgCj8ZPEcLc7vE6F

  1. 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

https://lh7-rt.googleusercontent.com/docsz/AD_4nXfbV4-yKPfz0i2dWxKTYQxdrTwgKeHBe3cijVcNRqd8n95L8hNQKILUVO6UZmowbppkx-lwsBhe_lr9ZETiYJzm3Si0Ja1u3Pn-WgfMz2E5_LlaaBN18EaybpieLVZVsng_xYF7?key=yQysIUu6sgCj8ZPEcLc7vE6F

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

  1. Download the hMailServer software from the official website.

  2. 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

  1. Launch the hMailServer Administrator. On your first run, you will be asked to enter the password you set during installation.

  2. Click on the Connect button on the top right to access the hMailServer Administrator console.

  3. Click on Domains from the sidebar on the left. This will open a modal on the right.

  4. 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.

  5. 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

  1. Tap Save to finish setting up the account.

  2. Now, go to Settings > Protocols > SMTP from the left sidebar. Uncheck POP3 and IMAP and click Save.

  3. 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.

  4. Now, go back to the Settings thread, but this time, select Advanced > IP Ranges. Here, remove the internet range.

  5. 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.

  6. 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:
  1. Go to Settings > Protocols > SMTP from the left-hand side.

  2. Go to the Delivery of Email tab.

  3. 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:
  1. Go to Settings > Protocols > SMTP and open the Delivery of Email tab.

  2. Leave the SMTP relayer section blank.

  3. 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.

  1. 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

  1. 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.

  2. Type an email and try to send it.

  3. If the test email doesn’t send successfully, review your SMTP settings. You can use the hMailServer built-in diagnostic tool to do this:

  4. Go to hMailServer Administrator > Utilities > Diagnostics.

  5. Choose your domain.

  6. 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

  1. Launch the Terminal app from the Applications > Utilities folder.

  2. Run the following command to check if Postfix is already installed:

postfix -v

Tip: If installed, this command will display your postfix version information.

  1. If it’s not installed, you can install it using Homebrew with the command:

brew install Postfix

Configuration

  1. Once Postfix is installed, open the Postfix configuration file using a text editor like Nano:

sudo nano /etc/postfix/main.cf

  1. 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

  1. After making these changes, press CTRL+X, then press Y to confirm, and hit Enter to save.

  2. 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

  1. 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

  1. Postfix needs a hash database to read the password file. Create it by running:

sudo postmap /etc/postfix/sasl_passwd

  1. Finally, restart Postfix to apply your changes by typing:

sudo Postfix reload

Testing

  1. 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
  1. Check your inbox to ensure the message was delivered successfully.

  2. 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

cta-img

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.

FAQs

SMTP is used for sending emails, while IMAP and POP3 are used for receiving them. For example, when you send an email through Gmail, SMTP sends it out. On the other hand, when you check your inbox, IMAP or POP3 brings the email to your device.

Yes, you can set up an SMTP server without a domain, but it is not recommended. Without a domain, your emails may not look credible and could get flagged as spam by other email services.

SMTP servers use ports 25, 465, and 587. Port 25 is used for sending emails between servers but can get blocked to stop spam. When that happens, port 465 (with SSL) or port 587 (with STARTTLS) is used for secure and safe email sending.

Yes, you can set up an SMTP server on macOS using third-party software like Postfix or Mailspring. While macOS doesn't include Postfix by default, with Homebrew, you can install it easily.

What should you do next?

You made it till the end! Here's what you can do next to grow your business:

2_1_27027d2b7d
Get smarter with email resources

Free guides, ebooks, and other resources to master email marketing.

1_2_69505430ad
Do interactive email marketing with Mailmodo

Send forms, carts, calendars, games and more within your emails to boost ROI.

3_1_3e1f82b05a
Consult an email expert

30-min free email consultation with an expert to fix your email marketing.

Table of contents

chevron-down
What is an SMTP server?
Pros and cons of running your own SMTP server
How to set up an SMTP server
What's a better alternative?
Final thoughts

Fresh Marketing Ideas, Every Week.

Get the latest marketing roundup & news

Get 3X email conversion
with Mailmodo

Check.svg

Create & send interactive emails without coding

Check.svg

Put revenue on auto-pilot with pre-built journeys

Check.svg

Save time with AI-powered email content creation

Experience world’s only interactive email marketing platform

Trusted by 10000+ brands

Group_1110166020_1_6fb9f2bd9a
Group_1110165532_1_bf39ce18b3
Ellipse_Gradientbottom_Bg
Ellipse_GradientLeft_Top
gradient_Right