Laravel SMTP setup - Things you should know

Submitted by lwinmaungmaung on
Image by Alexas_Fotos from Pixabay

Laravel is one of the most famous PHP frameworks. In the same way, email becomes widely used and they are now become playing a vital part in our daily lives. Many apps support sending emails via web apps such as OTP Tokens and reminders. So, the Laravel SMTP setup is important when we haven't set up before. 

Laravel SMTP Setup 1: API

Laravel support sending emails via API. Laravel support mandrill(drop support in Laravel 6.0), Mailgun and other providers include Postmark, SparkPost, Amazon SES. They can be programmed to send emails via API.

To send the emails via API, you can setup .env file or in config/mail.php to send the emails via API. 

You can get credentials via the dashboard interface and put the app key and secret to specific providers.

You can read more at https://laravel.com/docs/5.8/mail#introduction

Laravel SMTP Setup - Email for your domain promo - Lovely Family Host

Laravel SMTP Setup: SMTP

Many people stuck in working with SMTP when trying to send with the providers who do not provide API interface. 

There are one main thing different between SMTP in local and SMTP in the production server. The difference is port management. In the local development environment, the SMTP port is using 25 and plain authentication for your app. In a production environment, most SMTP servers are working with secure protocols, such as SSL and TLS. 

In working with SSL and TLS, they also provide specific ports for working with SMTP, 465 and 587. 465 is secure SMTP port and 587 is submission port for postfix or exim. They are working the same but both ports are widely used other than port 25. In Myanmar, port 25 is nationally reserved by YTP Teleport. So, if you connect SMTP via port 25, you will arrive in YTP relay instead of your intended SMTP server.

In connection to SMTP from Laravel, there is another thing you have to take care of email providers who support SMTP is they are protected by web authentication, especially Gmail. When connecting Gmail via SMTP, you will be redirected to login via the web interface to allow login. Most web clients and Mail Clients obey the instruction of OAuth to save credentials and protection to your account. That's why when you are trying to connect properly via port 587 or 465, sometimes you will get blocked.

Another difference is port 25 is not encrypted, means your data passed through port 25 is clearly visible by anybody. However, 465 and 587 is different in nature. They are fully protected with SSL and you can transfer your data fully. The difference is like telnet and SSH.

You also need to pass the encryption parameter 

Server Side - Firewall

In server management side, they do not have to do anything unless they are in strict environment. If the server blocked everything. As far as I know, many servers allow requesting specific port to another server. If they are blocked, you have to allow port 465 and 587 and make sure tls connection is turned on. Otherwise, your connection to your provider will fail successfully.

Category