This article talks about and explains some of the major queries developers have about SMTP Server. We have compiled this article with some of the prominent questions like What is an SMTP Server, Difference between SMTP and API, which service, between SMTP or API should you choose. Alternatively, we have also talked about configuring your SMTP Server to send unlimited transactional emails.
Table of Contents
- What is an SMTP Server
- SMTP Server Model
- Configuring SMTP Server
- Challenges while Configuring SMTP Server
Ask anyone ‘What does SMTP mean?’ and the first thing that pops to their mind is ‘Simple Mail Transfer Protocol’. Let’s go beyond the proverbial definition and understand what exactly is SMTP and SMTP Server, and why we need it. If you are familiar with the working of emails, you can send and receive Emails via SMTP server port. All the different programming languages and logical skills you’ve learned as a developer run only on your local computer/ server.
When you want to connect to the outside network and send an email/ SMS / notification, you’ll need a protocol called SMTP. Most email systems use SMTP to send email from one SMTP server port to another.
Alternatively, emails could also be sent from Email API and PHPMailer.
What is an SMTP Server?
An SMTP Server, also called as Simple Mail Transfer Protocol Server is essentially an application that sends, receives and relays emails. The major task of an SMTP Server is to act as a relay for outgoing mails between an email sender and an email receiver. It’s an important thing to note that SMTP Server is not actually a server but just an application which enables the sending and receiving of emails.
Every SMTP server has its own address which is usually in smtp.serveraddress.com format. A common doubt usually arises between SMTP and IMAP/POP. But there is a very subtle difference between the two.
SMTP is a push protocol and is used to send emails, whereas POP (post office protocol) or IMAP (internet message access protocol) is used to retrieve those emails at the receiver’s side.
The SMTP Server Model
The SMTP Server Model is of two types-
- End-to-end method
- Store-and- forward method
The end to end model is used to communicate between different organizations whereas the store and forward method are used within an organization. An SMTP client who wants to send the mail will contact the destination’s host SMTP directly in order to send the mail to the destination. The SMTP server will keep the mail to itself until it is successfully copied to the receiver’s SMTP.
The client SMTP is the one which initiates the session let us call it as the client- SMTP and the server SMTP is the one which responds to the session request and let us call it as receiver-SMTP. The client- SMTP will start the session and the receiver-SMTP will respond to the request.
Why use SMTP when we have Gmail/ Yahoo/ Outlook?
It’s true that most of us use web interfaces like Gmail, Yahoo, Outlook, etc to send our day-to-day personal and business emails. But one thing we need to understand is that all these platforms are built for sending 1:1 manual communication and are not designed for scale.
What do we mean by scaling my SMTP Server?
Yes, if you run an online business, you’ll be sending thousands of automated emails that are triggered basis users’ activity on the website – like sign up, password change, cart abandonment, etc. What you need is a system that can scale efficiently and in this scenario, sending emails from a web interface is not an option.
Why choose SMTP over API?
As an email sender, you are often confused between the two. SMTP or API, what to choose?
While SMTP is the more widely adopted of the two, there are some problems with SMTP as well. The back and forth communication issue of SMTP can be avoided with APIs, which in general have better delivery speeds and can be executed in a matter of seconds. Ultimately, the choice depends on your email needs (automation and tracking metrics) and the platform capabilities.
How to Send Emails using SMTP Server
You can either set up your SMTP server, or you can connect your email client with one of the SMTP Server Providers (one that is cloud-based and scalable, like Pepipost) and grant permission to deliver emails directly.
Some of you might think that setting up your own SMTP server might save cost. But come to think of it, it really doesn’t. Because each of the SMTP relay servers will have some limit on the number of emails it can deliver on various ISPs.
Even if you write a code that helps you scale and send millions of emails, sometimes ISPs will start blocking these emails thinking they are Spam because of the large volume of emails being sent by one sender at one time.
On the other hand, if you opt for a good Email Service Provider (ESP), you can send billions of emails, get email delivery expertise and build a high IP reputation. Choosing the right ESP is very critical. While sending emails in bulk, itis good to measure the performance of your emails because this will help build the reputation of your sender domain.
Hence, instead of handling infrastructure yourself, you can opt for a good ESP. It can assist you with tracking all user activities like email opens, clicks, bounces, spam complaints, and any other important activity.
You’ll find this blog useful in case you want to send emails with PHP from an SMTP server.
Step by Step Guide to Start Sending Emails from your SMTP Server
It’s very easy to send emails using SMTP. Almost all programming languages have an inbuilt function to make a connection to the SMTP relay server:
PHP –> mail() read more
Perl –> mail read more
Java –> JavaMail API read more
Below are the parameters which you require to make an SMTP connection:
Hostname: SMTP server location e.g. smtp.pepipost.com
Username: Username to authenticate the SMTP server
Password: Password to authenticate the SMTP server
Port no: 25, 587 or 2525
Using these four parameters you will be able to connect to any SMTP relay server and post that you will need to build the email file which consists of the Sender address, Recipient, Subject and Body. Creating this email file is also not rocket science, as every programming language has the functions to generate this file.
The above process is very similar to first making a database connection and then firing the SQL query.
Challenges Most Developers face while integrating SMTP
In case you are on a shared hosting server, the ports 25 and 587 remain blocked. This block is been purposely done by your hosting provider. This is true even for some of the dedicated servers. When these ports are blocked, try to connect using port 2525. If you find that port is also blocked, then the only solution is to contact your hosting provider to unblock these ports.
Read our comprehensive guide on SMTP Port Selection.
Most of the hosting providers block these email ports to protect their network from sending any spam emails.
Use ports 25 or 587 for plain/TLS connections and port 465 for SSL connections
For most users, we suggest port 587 to avoid rate limits set by some hosting providers.
I hope that by now you got an SMTP example and how it works. While this seems to be easy, there are some challenges you’ll face while using the default SMTP function.
In case your email volume is very less (maybe in a few thousand), then the default SMTP will work in your favor, but in case you are looking to generate millions of emails then the default SMTP might not scale.
The reason is –through one SMTP connection, you can send only one email. Hence to deliver a million emails, you’ll need to make 1 Million SMTP connections! That’s a lot of bandwidth and most importantly time-consuming, isn’t it?
You can get rid of making multiple SMTP connections using a couple of techniques.
Watch this exclusive video on Sending Mails Via SMTP.
1. Persistent SMTP Connection
The name itself is self-explanatory, all you have to do is make one SMTP connection and using the persistent SMTP function you can keep the same connection alive till it reaches the point of timeout. In this case, you can send multiple emails from just one SMTP connection. This concept is also known as SMTP Keep Alive.
One of the examples of using persistent SMTP connection in PHP:
phpMailer = New PHPMailer();
$phpMailer->isSMTP();$phpMailer->SMTPKeepAlive = true;
for ( … ) {
// Send your emails right away
[ … ]
}
$phpMailer->SmtpClose();
2. Have multiple processes running on the same machine
In case you are operating a business where your volume of emails run into double-digit millions, then there are further tricks to optimize the same.
Let’s take an example server on which 5 IP addresses are configured. Then write five mailing processes using SMTP persistent code each configured to connect with one separate IP. Hence, eventually, you will have 5 Persistent SMTP connections ready to fire emails.
Let’s say each of these persistent connections is capable of sending 100 emails/sec. That means, all five together will be able to send 500 emails in a second’s time. The actual throughput of emails ultimately depends on the configuration of the server, network speed, resource consumption, and lots more. You can further optimize the connections by using multiple physical machines or multiple machines under NAT.
One must understand that while this method of optimization can help you scale up your email volumes, you might get into trouble. You can be identified as a spammer, thereby causing your web servers to block your IP address.
When you are sending purely legitimate transactional/ digest/ notification types of emails on an opt-in user basis, the above optimization can help.
What about High Email Volumes SMTP Server Connection?
Sending one email is relatively simple. But for larger organizations that send millions of marketing or transactional emails, the SMTP process can get complicated. The best way to get started with SMTP email sending is by setting up a local mail server, such as Postfix. It is open-source and easy to configure.
You can submit all your emails to the local Postfix from your application and set up the SMTP of any ESP like Pepipost as a smart host in the relay settings. Here the Postfix is just been used as a queuing system. Even if the internet connectivity between your servers and ESP drops, your postfix installation is smart enough to queue up the emails and resend it once the connection is resumed. So, don’t worry about building the intelligence into your sending application for handling all these queues.
If you have any questions related to SMTP, or if you want to know more about how Pepipost as an ESP uses SMTP to send billions of emails every month, contact our 24×7 live chat support.
Also Read:
Check if emails from your domain are landing in Spam – Email Blacklist Checker Tool
Introduction to SMTP Relay Service
A Detailed Guide to SMTP Relay Service
SMTP Relay Service Guide – Scalable SMTP Service with Pepipost
Best SMTP Service Providers
Want to explore fascinating facets of email deliverability?
Learn from the best & gain a competitive edge for your email campaigns