Some cloud-based solutions such as Mailgun and SendPulse provide all the advantages above as well. However, all these features are paid, and you still have to rely on a third-party service. Instead, you can set up an SMTP server on your computer using a specific software.
Requirements for a local SMTP server
There are no specific requirements so far. Nevertheless, you should be prepared for the following:
- Some ISPs may block the port 25. You can solve this by contacting your ISP provider and learning about the limitations they may impose. Also, you need to request a correct DNS server and permission for MX record resolution.
- For bulk emails, you should probably opt for a domain and a fixed IP address associated with it – this will increase your resistance to spam filters.
Quick SMTP server setup
Now, let’s do the job. Since you’re going to set up an SMTP server on your computer, it’s crucial to know what OS is used. That’s why we’ll review three ways of how to do this for macOS, Windows, and Linux.
Important note: If you send test emails to the real email address, you might not find them in the inbox. Don’t forget to check the spam folder. ESPs like Gmail, Yahoo, and others are suspicious of new mail transfer agents.
For macOS
The latest versions of macOS X come pre-installed with Postfix – a default email server. So, all you need to do is tweak the SMTP server configuration as follows:
Postfix config file
- The Postfix main configuration file is the first to work with. Run:
sudo vim /etc/postfix/main.cf
- Tell Postfix which name it should use to identify itself to other mail servers. Add the following lines:
myhostname = john.example.com
myorigin = example.com
If your local username is John, the mail will appear to be from john@example.com.
- The relay host is the machine that will accept mails after authentication and relay them to the SMTP server.
relayhost=mail.example.com:25
- You need to enable SASL with an additional configuration file, where the password is stored.
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
- This line means that Postfix will only use TLS-encrypted connections.
smtp_tls_security_level = encrypt
- Here is how
main.cf
looks in full:
myhostname = john.example.com
myorigin = example.com
relayhost=mail.example.com:25
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
smtp_tls_security_level = encrypt
sudo postmap /etc/postfix/main.cf
File with SASL password
- Create the
sasl_passwd
file:
sudo vim /etc/postfix/sasl_passwd
mail.example.com:25 john@example.com:<your password>
sudo postmap /etc/postfix/sasl_passwd
sudo postfix reload
The local SMTP server is ready. Try it out by sending a test email:
date | mail -s "Test email" recipient@test.com
Note: this setup flow is suitable for non-macOS machines that have a regular Postfix daemon.
For Linux
Most Linux distributions are shipped with the two most common SMTP implementations: Sendmail and Postfix. Sendmail has quite a complex design and is less secure; that’s why we picked Postfix again.
Installation
If you don’t have Postfix on your machine, install it first. Also, you’ll need the mail package Mailutils, which includes programs necessary for Postfix to function:
sudo apt install mailutils postfix
In the Postfix Configuration window, you’ll need to choose the Internet Site mail configuration. Finally, you’ll need to specify the system mail name. It should be the same as the name you assigned to the domain name pointing to your server. Let’s use example.com.
Configuration
Now, let’s configure Postfix to process requests to send emails from localhost. For this, you need to tweak the main configuration file main.cf
:
sudo nano /etc/postfix/main.cf
Scroll down to the line inet_interfaces = all
and replace it with inet_interfaces = loopback-only
Also, you need to modify mydestination
, which specifies the list of domains. It should look like this:
mydestination = $myhostname, localhost.$example.com, $example.com
Save the file and restart Postfix with:
sudo systemctl restart postfix
At the end, try to send a test email:
echo "Test email body" | mail -s "Test email subject line" receipient’s_email_address
For Windows
There are several software options to set up an SMTP server on Windows including MailEnable and Apache James. But we’ve opted for the most popular one, called hMailServer.
Installation
Download the latest version here, and install it. At the beginning of the installation, you need to pay attention to the following:
- In the Select Components window, make sure that full installation is chosen. Server and Administrative components must be checked.
- In the Select database server type window, check the built-in database engine.
- In the hMailServer Security window, create a password for the default user.
Once installed, run hMailServer, and now let’s configure it.
Configuration
- Click Connect on the starting window and enter the password you set up during the installation.
- Click Add domain and enter your domain name in the corresponding field. By the way, you can use a fake domain name since the real one is not required to send emails. But, in this case, make sure that the fake domain does not actually exist. Click Save, and you’ll see your domain created in the left tab.
- Select the Accounts folder in the left tab and click Add… to configure one. All you need to do here is enter a name in the Address field. This will set up your email address. Optionally, you can specify a password. Click Save and head on to the Settings in the left tab.
- Expand the Settings thread and select Protocols. Uncheck POP3 and IMAP. For more on these protocols, read our blog post IMAP vs. POP3 vs. SMTP. Click Save.
- Now, select Advanced in the Settings thread and enter localhost in the Default domain field in the right tab. Click Save. To end up with the Advanced settings, select Auto-ban and uncheck the Enabled box. Click Save.
- In the end, expand the Utilities thread and select Diagnostics. Select your domain to run tests on and click Start. We’re not interested in all the tests, just Collect server details and Test outbound port. These ones should be marked green.
That’s it. Now you can send your test email. This can be done with PowerShell – it’s fast and easy. For more on this, read our blog post Send Emails from PowerShell. Run the following line (don’t forget to input your data):