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):