When we launched the first version of Geedesk we went with Sendgrid for all our emailing needs.
Sendgrid is a wonderful product and with it you can quickly set up an email workflow and get your product up and running.
As Geedesk got more users Sendgrid handled the load very brilliantly and the emails whizzed away to the recipients.
Our customer support team also loved the email delivery reports to check the status of emails if one of users complained about not receiving emails.
However in the recent years Sendgrid has become very expensive and also they are rejecting new account signups.
The pros vs cons of maintaining Sendgrid at a higher subscription does not make any more sense. This prompted us to look for alternates.
The market is filled with SMTP service providers. But all of them are pretty expensive.
Not to take anything away from them. They too have to run a company. All their higher tiers were expensive and us being an Indian company paying in dollars did not make any more sense.
This left us with only one option. That is to build our own solution.
As I had some experience with Exim in the past that naturally became the go to option.
I spun up an instance and installed Exim and configured it to send emails from our application.
Configuring it was quite simple and straightforward.
During the testing phase I was able to send encrypted and user authenticated emails from our Laravel backend by updating the environment files with the SMTP credentials.
With the SPF records in place the emails from Exim flowed into the recipient inbox without any issues.
Once we were satisfied with the testing it was time to add a layer of security to the Exim server.
The first level of security was to make Exim listen within a private network and not on the internet.
To further cut off Exim from the outside world we built a simple API with Laravel.
All our applications will be making a post request to this API with the right payload and this API will receive the payload, validate it and post to a RabbitMQ queue from where a worker will pick up and send the emails via Exim.
In Laravel I created a class that will make a curl call to the SMTP API. This made it very easy for our engineers as they need not modify the way emails were sent. The only change required was to change the API and the API key.
To make it as close to Sendgrid as possible I even maintained the same parameter names.
This might not be the best solution for everyone. We also do not recommend going this path and in the grand scheme of things using Sendgrid is the best way forward.
But we as a team were fed up with the expensive offerings in the market and the constant invoices in US dollars. Hence we decided to come up with our own SMTP API with Laravel and Exim.