Gmail SMTP server stopped working as it no longer support "Less Secure Apps"
Stefan Bogdanescu
Founder & Senior Architect
Fixing Laravel Email Issues: Moving Beyond "Less Secure Apps" for SMTP
As developers working with frameworks like Laravel, we often rely on external services to handle crucial tasks, such as sending transactional emails. Recently, many developers have encountered issues where their email functionality suddenly breaks. A common culprit is Google’s policy change regarding "Less Secure Apps," which effectively deprecated the old, insecure method of authenticating SMTP connections.
If you are running into trouble sending emails from your Laravel application, especially when trying to set up a local testing environment, understanding this shift is key to finding a robust solution. This post will walk you through why the old method failed and provide modern, secure alternatives for handling email delivery in your projects.
The Shift from Legacy SMTP to Modern Security
The reason your emails stopped working is directly related to security evolution. Services like Gmail have continuously tightened security protocols. The "Less Secure Apps" setting was a legacy mechanism that allowed less secure authentication methods. As these methods pose significant security risks, Google and other major providers phased them out entirely. This means any application attempting to use these older credentials for SMTP will be rejected by the mail server, leading to failed delivery attempts within your Laravel application.
Trying to force an old configuration to work now is futile because the underlying infrastructure no longer supports it. We need to pivot from insecure methods to modern, authenticated standards.
Modern Solutions for Sending Emails in Laravel
For any professional or even robust local testing setup, you should always prioritize secure authentication. Forget trying to resurrect outdated settings; instead, adopt established protocols.
Option 1: Using Secure Third-Party Services (Recommended)
The most reliable and scalable approach is to use dedicated transactional email services. These services handle the heavy lifting of deliverability, security, and rate limiting, freeing you from managing complex SMTP configurations directly. Services like SendGrid, Mailgun, or Amazon SES are industry standards.
When integrating these services into Laravel, you simply configure your .env file with their specific API keys and credentials. This approach is far safer than relying on personal Gmail accounts for application-level sending. For deeper dives into service integration within a framework context, understanding how to manage configuration securely is vital, much like when structuring components in a well-designed Laravel application where security considerations are paramount (see best practices discussed at laravelcompany.com).
Option 2: Local Development and Testing Setup
If your goal is purely local development—testing how your application handles email logic without actually sending sensitive emails to external servers—you do not need a live SMTP server setup immediately.
Instead, leverage Laravel’s built-in testing features or use specialized tools for simulation:
- Mailtrap/Mailhog: These services act as SMTP sandboxes. They intercept outgoing emails and store them in a dashboard, allowing you to inspect the email content locally without risking real delivery failures. This is perfect for debugging your Laravel mail configuration immediately.
- Mocking: For unit testing, use mocking libraries to simulate successful or failed email deliveries, ensuring your application logic remains testable regardless of external service status.
Code Example: Configuring Laravel Mail
Regardless of which provider you choose (or even if you are setting up a local test), the configuration in your .env file is the foundation. Here is how you typically set up an SMTP connection for a service like Mailtrap or a secure provider:
# .env file example
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=YOUR_MAILTRAP_USERNAME
MAIL_PASSWORD=YOUR_MAILTRAP_PASSWORD
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"
By using these modern methods, you bypass the obsolete "Less Secure Apps" restrictions entirely and ensure your Laravel application maintains high standards of security and deliverability.
Conclusion
The demise of the "Less Secure Apps" feature was a necessary step toward securing email infrastructure. As senior developers, our responsibility is to adapt quickly to these changes by adopting secure protocols. Do not waste time trying to fix legacy configurations. Instead, embrace modern API-driven services and local testing sandboxes like Mailtrap. By doing so, you ensure your Laravel projects are not only functional but also secure and scalable.