Join us
@sofiatarhonska ・ Oct 12,2022 ・ 7 min read ・ 836 views ・ Originally posted on mailtrap.io
In the blog post Best Free SMTP Servers, we touched on the cloud-based solutions for sending emails. These are quite common for all sizes of projects. But what if you don’t want to use the email relay services of Gmail SMTP or its alternatives? In this article, we’ll teach you how to set up a local SMTP server and get rid of any email-sending dependencies.
Using an outgoing SMTP server is the traditional method of sending emails. An alternative solution is to bypass the SMTP server and send directly to the destination. It’s known as Direct Send, and you can use it through specific email software programs. Direct Send is not very reliable though, and here is why:
Let’s put Direct Send away. What you may be interested in is why you would run your own SMTP server.
Pros | Cons |
---|---|
no daily or hourly limit on the number of outgoing emailsinstant reportingprivacy and control of all your outgoing mailno shared IP | running a local SMTP server takes time and effortthe bounce rate may increase by 20-30% |
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.
There are no specific requirements so far. Nevertheless, you should be prepared for the following:
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.Â
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:
sudo vim /etc/postfix/main.cf
myhostname = john.example.com
myorigin = example.com
If your local username is John, the mail will appear to be from john@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
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
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.
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.
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.Â
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
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.Â
Download the latest version here, and install it. At the beginning of the installation, you need to pay attention to the following:
Once installed, run hMailServer, and now let’s configure it.
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):
In the pop-up window, you’ll need to enter your password.Â
In most cases, people set up local SMTP servers for testing purposes. If you’re developing an app that will send emails, you’ll need to test this function, and a real SMTP server running on your local machine might seem to be a good option. But, is it?Â
On the one hand, it’s not troublesome to install and configure a local SMTP server. However, there is a much better solution.
Mailtrap Email Sandbox is a safe environment that allows developers to test, inspect, and debug emails. All of this can be done at staging, meaning your app can send an email, but it won’t
be delivered to the actual recipient.
Instead, the test email will go to the Sandbox’s inbox. Thus there are no risks of spamming users.
From the inbox, it’s possible to validate your email’s HTML/CSS and quickly see spam analysis results that are verified by the Apache SpamAssassin filter.Â
Unlike with a regular SMTP server, there is no lengthy installation process. All you have to do is update your SMTP settings with the relevant credentials:
Alternatively, you can copy and paste a ready-to-use code snippet that appears once the relevant language is selected from the drop-down menu.
Running a local mail server can sometimes be a pain. A great deal of knowledge and effort are required to achieve good email deliverability using your own SMTP server. Perhaps it is a good option for testing purposes, but Mailtrap, or other email testing tools, will do it better. So, do you actually need a local SMTP server? You are the only one that can answer that. Good luck!
Thanks for reading our guide on how to configure smtp server in Windows that was originally published on Mailtrap Blog.
Join other developers and claim your FAUN account now!
Influence
Total Hits
Posts
Only registered users can post comments. Please, login or signup.