How To Set Up SMTP Server With Postal (Step By Step Guide)
In this Step by Step Guide, we will show you how to set up a SMTP server using Postal, the open-source SMTP software to Send Unlimited Emails.
There are several methods to build SMTP servers, in this guide we will build the SMTP server using a free open source software called “Postal“.
Postal is a fully-featured open-source mail delivery platform for incoming & outgoing e-mail and gives you all the tools and features needed to build a full mailing system for your business.
What is the SMTP Server?
We have described it in detail about this in our another blog “What is a SMTP Server?“. But if you want know it in brief, here it is:
SMTP is that thing that allows you to send emails over the internet.
SMTP stands for “Simple Mail Transfer Protocol”. It's a Concept in Networking that you don't have to worry about.
Just Know that SMTP is the technical thing that is responsible for delivering emails over the internet.
What do we mean by Sending Unlimited Emails?
When we say unlimited emails, this means that we can send unlimited emails from our server, there are no restrictions by companies or monthly plans to buy or so.
It's your server, you can send as much as your server can handle in terms of resources. So when you have more CPU and RAM, you can send more emails and so on.
Let's Start The SMTP Server Setup
Ok, let's start the real work! But, before we start, you need to know what is required.
Requirements to Setup SMTP Server.
In order to Build and Setup an SMTP Server, you will mainly need two things:
- A Domain Name
- VPS Server with Port 25 Opened.
1. Domain name
When you send emails, you will be sending from an email address like this one:
So in our case, “sapnaaz.com” is the domain name that we use to send our emails. It's required to have a domain name to use when you send emails from your SMTP server.
Usually, it's your website domain name, except if you are working with cold emails, then it's better to get and use another domain in case it got blacklisted, to keep your main business domain safe.
So if you don't have a domain yet, go and get one now in order to continue the setup.
How to get a domain? Simply you buy one! And it costs around 10$/year, so it's not that big deal!
We have a lot of DOMAIN REGISTRATION PROVIDERS where you can get a domain from, like:
Here in this course, we will be using Namecheap to get my domain, but you can use any other service if you want, all work in the same way, and if you need any help, we will be here 🙂.
Got a Domain? Great! ✔️ Let's continue.
2. VPS Server with Port 25 opened.
The second thing you will need is a VPS server, a public server to Install & Setup SMTP on.
What is a VPS server?
If you don't know what is a VPS server, simply it's a computer (a server) running in the cloud that you buy from a Web Hosting or Cloud Services company. And it's publicly accessible with a Public IP.
A VPS can be used to host your websites with higher performance and can be used to run a machine 24/7 in the cloud to do any task you want.
Port 25 open??
We mentioned that the VPS must have port 25 opened, what does this mean?
We don't want to bother your head dealing with technical stuff but, in short, any network service or software uses a certain port to communicate over the internet or network. For example:
- Connecting remotely to another Windows Machine using RDP software works over port 3389.
- SQL database systems like MYSQL on our computer works over port 3306.
- Connecting to a Linux machine remotely to manage it with SSH, uses port 22.
- When you surf the web and open websites, we use port 80. and so on.
By default, all servers and computers have a firewall running which blocks all ports except the ones you want. So, to use a certain service, we need to open that port in the firewall.
What you have to know also, that ports can be blocked and opened in two ways, incoming and outgoing, the following diagram will make things clearer:
In our case, we are building an SMTP server, and the SMTP software or protocol communicates over port 25. So, we need to have port 25 opened.
When you get a VPS server, just make sure that the company allows Port 25 and don't block it, because some companies do this to protect from spammers.
Here is a list of some companies that allows port 25 by default:
- AWS (some accounts are blocked)
Are there any other Companies? Yes, you can contact the support of any company you want and ask if they block any ports by default. If not, then perfect, you can go with it.
Feel free to use any VPS company you want, It's up to you!
You can also sign up on DigitalOcean through this coupon link to get free $100 to test everything for free.
Or start with Contabo which we think is the cheapest VPS service that you can use, we have 2 servers configured with Contabo.
After you select your VPS company, just create a VPS Server with the following minimum specifications:
- Ubuntu 22.04 or 20.04 or 18.04 x64 as your operating system
- You can start with 1 CPU/2 GB RAM (And resize later).
Got your VPS? Great! ✔️ Let's continue.
VPS Server basic configuration
Now we have our new Ubuntu VPS server, let’s prepare it out for setup.
Connect to your server, using an SSH client like putty or bitvise. Or if you do not like to install these softwares and you are using Windows 10/11 or Linux or Mac OS then you can do the following:
- Press Win + R on your keyboard.
- Type cmd, and press Enter. A new window will open.
- In the window, type ssh username@ip-address (replace username with the username of your server and ip-address with the IP address of your server)
First, check your hostname:
If you don’t see a form of ANYTING.YOURDOMAIN.COM, then you need to change the hostname using the following command:
sudo hostname server.domain.com
Where the host is anything you want. Our domain for this tutorial is sapnaaz.com, so the command will look like this:
sudo hostname postal.sapnaaz.com
Map your domain name
Now we have our VPS server and we set its name. Go to your Domain Provider and map your Domain to your VPS server. Just open DNS management zone and add a new A record like this:
Host: postal (Whatever you have chosen) Points To: YOUR_SERVER_IP
Done? ✔️ Let's continue.
The VPS is ready, and we can start the installation process. To setup SMTP Server on our VPS, we need to install an SMTP software.
Install Postal Mail Server on Ubuntu 22.04/20.04/18.04
The installation of Postal Mail Server on Ubuntu is not as complicated as others say. By sparing some minutes and following below few steps, you should have Postal Mail Server running on Ubuntu 22.04/20.04/18.04 server.
Step 1: Update your system
Like all other installations, we start the installation by ensuring our system is updated.
sudo apt update sudo apt -y upgrade
Perform a reboot if it is required:
[ -f /var/run/reboot-required ] && sudo reboot -f
Then install git once the system is up
sudo apt -y install git curl jq
Step 2: Install Docker & Docker Compose
Import Docker repository GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/docker-archive-keyring.gpg
With GPG key imported you can add Docker repository to your Ubuntu system.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Finally install Docker CE on Ubuntu 22.04/20.04/18.04:
sudo apt update sudo apt install docker-ce docker-ce-cli containerd.io
Add your user account to docker group.
sudo usermod -aG docker $USER newgrp docker
Confirm successful installation by checking Docker version
$ docker version Client: Docker Engine - Community Version: 20.10.16 API version: 1.41 Go version: go1.17.10 Git commit: aa7e414 Built: Thu May 12 09:18:18 2022 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.16 API version: 1.41 (minimum version 1.12) Go version: go1.17.10 Git commit: f756502 Built: Thu May 12 09:16:22 2022 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.4 GitCommit: 212e8b6fa2f44b9c21b2798135fc6fb7c53efc16 runc: Version: 1.1.1 GitCommit: v1.1.1-0-g52de29d docker-init: Version: 0.19.0 GitCommit: de40ad0
Download the latest Compose
curl -s https://api.github.com/repos/docker/compose/releases/latest | grep browser_download_url | grep docker-compose-linux-x86_64 | cut -d '"' -f 4 | wget -qi -
Make the binary file executable.
chmod +x docker-compose-linux-x86_64
Move the file to your PATH.
sudo mv docker-compose-linux-x86_64 /usr/local/bin/docker-compose
$ docker-compose version Docker Compose version v2.6.1
Step 3: Install MySQL / MariaDB database server
The other requirement of Postal Mail server is a database server.
Now, you can install MariaDB in the docker container.
docker run -d \ --name postal-mariadb \ -p 127.0.0.1:3306:3306 \ --restart always \ -e MARIADB_DATABASE=postal \ -e MARIADB_ROOT_PASSWORD=postalpassword \ mariadb
Step 4: Install and Configure RabbitMQ
Postal uses RabbitMQ for queueing. RabbitMQ is necessary to process messages and distribute the loads
To install it, run the following commands
docker run -d \ --name postal-rabbitmq \ -p 127.0.0.1:5672:5672 \ --restart always \ -e RABBITMQ_DEFAULT_USER=postal \ -e RABBITMQ_DEFAULT_PASS=password \ -e RABBITMQ_DEFAULT_VHOST=postalvhost \ rabbitmq:3.8
Now we have installed all the prerequisite packages, it’s time to install Postal
Step 5: Install and Configure Postal on Ubuntu 22.04/20.04/18.04
Cloning the Postal repository
sudo git clone https://postalserver.io/start/install /opt/postal/install
Create a symlink for Postal binary
sudo ln -s /opt/postal/install/bin/postal /usr/bin/postal
You’ll need these records for accessing the API, management interface & SMTP server.
You can configure a global SPF record for your mail server which means domains don’t need to each individually reference your server IPs. This allows you to make changes in the future.
|spf.postal.yourdomain.com||TXT||v=spf1 ip4:Your_Server_IP ~all|
If you wish to receive an incoming e-mail by forwarding messages directly to routes in Postal, you’ll need to configure a domain for this just to point to your server using an MX record.
The return path domain is the default domain that is used as the MAIL FROM for all messages sent through a mail server. You should add DNS records as below.
|rp.postal.yourdomain.com||TXT||v=spf1 a mx include:spf.rp.postal.yourdomain.com ~all|
Run the command below and replace postal.yourdomain.com with the actual hostname you want to access your Postal web interface at.
$ sudo postal bootstrap postal.example.com Latest version is: 2.1.1 => Creating /opt/postal/config/postal.yml => Creating /opt/postal/config/Caddyfile => Creating signing private key
This will generate three files in /opt/postal/config.
- postal.yml is the main postal configuration file
- signing.key is the private key used to sign various things in Postal
- Caddyfile is the configuration for the Caddy webserver
Open Postal configuration file.
sudo vim /opt/postal/config/postal.yml
At the minimum, have the following settings:
web: # The host that the management interface will be available on host: postal.yourdomain.com # The protocol that requests to the management interface should happen on protocol: https main_db: # Specify the connection details for your MySQL database host: localhost username: root password: postalpassword database: postal message_db: # Specify the connection details for your MySQL server that will be house the # message databases for mail servers. host: localhost username: root password: postalpassword prefix: postal rabbitmq: # Specify the connection details for your RabbitMQ server. host: 127.0.0.1 username: postal password: password vhost: postalvhost dns: # Specifies the DNS record that you have configured. Refer to the documentation at # https://github.com/atech/postal/wiki/Domains-&-DNS-Configuration for further # information about these. mx_records: - mx.postal.yourdomain.com smtp_server_hostname: postal.yourdomain.com spf_include: spf.postal.yourdomain.com return_path: rp.postal.yourdomain.com route_domain: routes.postal.yourdomain.com track_domain: track.postal.yourdomain.com smtp: # Specify an SMTP server that can be used to send messages from the Postal management # system to users. You can configure this to use a Postal mail server once the # your installation has been set up. host: 127.0.0.1 port: 2525 username: # Complete when Postal is running and you can password: # generate the credentials within the interface. from_name: Postal from_address: email@example.com
Edit the file to fit your Postal settings.
When done Initialize database by adding all the appropriate table:
$ sudo postal initialize [+] Running 5/5 ⠿ smtp Pulled 0.5s ⠿ cron Pulled 0.5s ⠿ requeuer Pulled 0.5s ⠿ worker Pulled 0.5s ⠿ web Pulled 0.5s Initializing database ......
Create your initial admin user
Add your Email, Name & Suitable Password (Remember this email and password as this will be required to login to postal)
$ sudo postal make-user Postal User Creator Enter the information required to create a new Postal user. This tool is usually only used to create your initial admin user. E-Mail Address : firstname.lastname@example.org First Name : Admin Last Name : User Initial Password: : ******** User has been created with e-mail address email@example.com
Starting the application
Run the following command to start the Postal application
$ sudo postal start [+] Running 5/5 ⠿ Container postal-cron-1 Started 0.4s ⠿ Container postal-web-1 Started 0.2s ⠿ Container postal-requeuer-1 Started 0.3s ⠿ Container postal-smtp-1 Started 0.3s ⠿ Container postal-worker-1 Started 0.3s
This will run a number of containers on your machine.
You can look at the status at any time using:
$ sudo postal status NAME COMMAND SERVICE STATUS PORTS postal-cron-1 "/docker-entrypoint.…" cron running postal-requeuer-1 "/docker-entrypoint.…" requeuer running postal-smtp-1 "/docker-entrypoint.…" smtp running postal-web-1 "/docker-entrypoint.…" web running postal-worker-1 "/docker-entrypoint.…" worker running
Step 6: Configuring Caddy Web Server
A web proxy is required for all web traffic and SSL termination. There are many options for Proxy – Nginx, Apache, HAProxy, e.t.c. In this guide, we’re going to use Caddy.
We can run Caddy web server using Docker:
docker run -d \ --name postal-caddy \ --restart always \ --network host \ -v /opt/postal/config/Caddyfile:/etc/caddy/Caddyfile \ -v /opt/postal/caddy-data:/data \ caddy
Check it’s running:
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 67461a34ae39 caddy "caddy run --config …" 20 seconds ago Up 20 seconds postal-caddy 1bc1bac79c15 ghcr.io/postalserver/postal:2.1.1 "/docker-entrypoint.…" About a minute ago Up About a minute postal-smtp-1 c5a04cea4211 ghcr.io/postalserver/postal:2.1.1 "/docker-entrypoint.…" About a minute ago Up About a minute postal-worker-1 e188ee4c2844 ghcr.io/postalserver/postal:2.1.1 "/docker-entrypoint.…" About a minute ago Up About a minute postal-requeuer-1 d7335cd48fa1 ghcr.io/postalserver/postal:2.1.1 "/docker-entrypoint.…" About a minute ago Up About a minute postal-web-1 c4b1cc7a852e ghcr.io/postalserver/postal:2.1.1 "/docker-entrypoint.…" About a minute ago Up About a minute postal-cron-1
Once this has started, Caddy will issue an SSL certificate for your domain and you’ll be able to immediately access the Postal web interface and login with the user you created in one of the previous steps.
Once you have installed Postal, you can upgrade to the latest release it by running this command:
$ sudo postal upgrade warning: redirecting to https://github.com/postalserver/install/ From https://postalserver.io/start/install * branch main -> FETCH_HEAD Already up to date. No version specified, using latest available version... Upgrading to 2.1.1 [+] Running 5/5 ⠿ worker Pulled 1.5s ⠿ cron Pulled 0.5s ⠿ web Pulled 0.4s ⠿ smtp Pulled 0.5s ⠿ requeuer Pulled 0.5s Migrating database [+] Running 5/0 ⠿ Container postal-worker-1 Running 0.0s ⠿ Container postal-web-1 Running 0.0s ⠿ Container postal-smtp-1 Running 0.0s ⠿ Container postal-requeuer-1 Running 0.0s ⠿ Container postal-cron-1 Running 0.0s
Step 7: Access Postal Admin Web Dashboard
Access Postal Administration page on https://postal.yourdomain.com
You should see Let’s Encrypt SSL certificate in place if your installation was successful and login with admin user email created earlier.
You’ll get a dashboard which looks like this:
Create your first organization
Provision mail server to start sending and receiving messages using Postal.
Give your mail server a name and choose live mode.
With the basic configurations required you can now use Postal email delivery software solution.
Refer to the Postal Administration guide for further configurations.
Congratulations! You have completed setting up your own Free SMTP Server using Postal. But before you start sending emails, you have to understand some crucial concepts and follow up on the guidelines to get the best delivery rates and reach the inbox!
- Warming Up your SMTP server – We will be updating a blog about this very soon.
- rDNS (Reverse DNS)
- DMARC (Domain-based Message Authentication, Reporting & Conformance)
- MX Record
- Avoid Spam Factors – IP Reputation, SPF, DKIM, DMARC, Message Body, Email List health.
If you are having difficulties in setting up the SMTP server, you can order our service for creating it here or you can ask your questions in the comments below or in the forum.
What is a SMTP Server?
Email is among the widely used communication channel, and most internet system uses Simple Mail Transfer Protocol SMTP to transfer email from their server to the recipient’s server.
It’s a standard communication protocol used by mail servers and other message transfer agents and can impact the deliverability of your campaigns.
This guide will discuss what SMTP is and how it works in the email marketing landscape.
What is the Simple Mail Transfer Protocol (SMTP)?
The Simple Mail Transfer Protocol (SMTP) is a technical standard for transmitting electronic mail (email) over a network. Like other networking protocols, SMTP allows computers and servers to exchange data regardless of their underlying hardware or software. Just as the use of a standardized form of addressing an envelope allows the postal service to operate, SMTP standardizes the way email travels from sender to recipient, making widespread email delivery possible.
SMTP is a mail delivery protocol, not a mail retrieval protocol. A postal service delivers mail to a mailbox, but the recipient still has to retrieve the mail from the mailbox. Similarly, SMTP delivers an email to an email provider's mail server, but separate protocols are used to retrieve that email from the mail server so the recipient can read it.
What is a protocol?
A protocol consists of a set of rules and procedures which govern the exchange of data between two or more devices. Protocols define how data transmission will occur between electronic devices such as computers. They set the standard procedures for communication and the exchange of information.
The International Organization for Standardization established the Open Systems Interconnection (OSI). One such widely used Internet protocol lays down the standard for communication over different networks. The model divides the process of data transmission into a series of seven layers.
Important internet protocols are TCP/IP, HTTPS, DNS, and SMTP.
What is an SMTP server?
An SMTP server is a mail server that can send and receive emails using the SMTP protocol. Email clients connect directly with the email provider's SMTP server to begin sending an email. Several different software programs run on an SMTP server:
- Mail submission agent (MSA): The MSA receives emails from the email client.
- Mail transfer agent (MTA): The MTA transfers emails to the next server in the delivery chain. As described above, it may query the DNS to find the recipient domain's mail exchange (MX) DNS record if necessary.
- Mail delivery agent (MDA): The MDA receives emails from MTAs and stores them in the recipient's email inbox.
Common SMTP server providers & settings
|SMTP Provider||URL||SMTP Settings|
How does the SMTP work?
The Transmission Control Protocol (TCP) is the primary connection for communication between the mail sender and the mail receiver. In SMTP, the mail sender sends the data in command strings over this reliable ordered data stream channel.
The SMTP client, the initiating agent, sender, or transmitter, initiates the communication session. It issues the command strings and opens the session for corresponding responses from the SMTP server, which involves the listening agent or receiver. Zero or more SMTP transactions may be there in a course.
Usually, an SMTP email transaction follows four command or reply sequences:
It tells the email server that the client wants to start the mail transaction. The client mentions its domain name after this command.
It lays down the bounce address/return address, defining the return or reverse paths.
It specifies the recipient of the message. The sender’s envelope contains the addresses of the recipients, to which the RCPT command can be issued multiple times for each recipient.
It shows where the content of the message starts, as opposed to its envelope. An empty line separates the message header and body in the message’s text.
DATA is not just one command but a group of commands in which a server has to reply twice
- First, the server acknowledges the message and replies with its readiness to take the message.
- Then after completing the end-of-data sequence, it either accepts or rejects the entire message.
Apart from the reply of the DATA command, the server can reply in a positive way (2xx reply codes) or a negative way.
The negative responses can further be permanent (5xx codes) or transient (4xx codes).
If a server sends ‘reject,’ then it is a permanent failure, and the client needs to send a bounce message to the respective server. On the other side, a ‘drop’ is a positive reply in which the message is discarded instead of delivered.
What is an SMTP envelope?
The SMTP “envelope” is the set of information that the email client sends to the mail server about where the email comes from and where it is going. The SMTP envelope is distinct from the email header and body and is not visible to the email recipient.
What port does SMTP use?
In networking, a port is a virtual point where network data is received; think of it as the apartment number in the address of a piece of mail. Ports help computers sort networking data to the correct applications. Network security measures like firewalls can block unnecessary ports to prevent the sending and receiving of malicious data.
Historically, SMTP only used port 25. Today, port 25 is still in use for SMTP, but it can also use ports 465, 587, and 2525.
- Port 25 is most used for connections between SMTP servers. Firewalls for end-user networks often block this port today, since spammers try to abuse it to send large amounts of spam.
- Port 465 was once designated for use by SMTP with Secure Sockets Layer (SSL) encryption. But SSL was replaced by Transport Layer Security (TLS), and modern email systems, therefore, do not use this port. It only appears in legacy (outdated) systems.
- Port 587 is now the default port for email submission. SMTP communications via this port use TLS encryption.
- Port 2525 is not officially associated with SMTP, but some email services offer SMTP delivery over this port in case the above ports are blocked.
Difference between SMTP, IMAP, & POP3
The Internet Message Access Protocol (IMAP) and Post Office Protocol (POP) are used to deliver the email to its final destination. The email client has to retrieve the email from the final mail server in the chain to display the email to the user. The client uses IMAP or POP instead of SMTP for this purpose.
To understand the difference between SMTP and IMAP/POP, consider the difference between a plank of wood and a rope. A length of wood can be used to push something forward, but not pull it in. A rope can pull an item, but cannot push it. Similarly, SMTP “pushes” email to a mail server, but IMAP and POP “pull” it the rest of the way to the user's application.
What is Extended SMTP (ESMTP)?
Extended Simple Mail Transfer Protocol (ESMTP) is a version of the protocol that expands upon its original capabilities, enabling the sending of email attachments, the use of TLS, and other capabilities. Almost all email clients and email services use ESMTP, not basic SMTP.
ESMTP has some additional commands, including “EHLO”, an “extended hello” message that enables the use of ESMTP at the start of the connection.
SMTPs are essential for sending and receiving emails. However, as an email marketer, you need to choose and configure the SMTP service providers that suit your requirements.
At Sapnaaz, we provide easy SMTP setup and integration with any SMTP servers you might like to send your email marketing campaigns. Feel free to reach out to the Sapnaaz team to learn more or check out our SMTP setup service page.