Gmail SMTP server stopped working as it no longer support "Less Secure Apps"

Gmail SMTP server stopped working as it no longer support "Less Secure Apps"

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Gmail SMTP server stopped working as it no longer support "Less Secure Apps"

If you are maintaining a Laravel application that relies on Gmail for sending emails, you may have encountered a sudden failure in your mail delivery pipeline. The error often manifests as an authentication failure or a generic connection refusal, leaving you stuck with outdated documentation pointing toward a setting called "Less Secure Apps." Google officially deprecated this feature to enhance security, and the option has been removed from the user account dashboard. Consequently, the legacy method of using gmail-smtplogin with your full password is no longer viable for sending mail through their SMTP servers.

To restore functionality, you must pivot to modern authentication standards. The current requirement is to implement an App Password or migrate to OAuth 2.0 if your application supports it. For most existing Laravel deployments, switching to an App Password is the most pragmatic solution with minimal code changes.

Enabling Two-Factor Authentication and Generating App Passwords

Before configuring your SMTP settings, there are strict prerequisites that must be met. First, your primary Gmail account must have 2-Step Verification enabled. Without this security layer in place, Google will not allow the generation of App Passwords. You can enable this via the Google Account security settings page.

Once 2-Step Verification is active, you can generate a dedicated password for SMTP access:

  1. Navigate to your Google Account security section.
  2. Locate App passwords under the "Signing in to Google" menu.
  3. Select the application type as "Other (Custom name)" and enter a descriptive label, such as Laravel-Localhost.
  4. Generate the password and copy the 16-character string.

Do not use your main account password for this purpose. Attempting to do so will result in authentication errors because Google treats any attempt to log in with the master password from an app without OAuth tokens as a security risk now that "Less Secure Apps" is gone.

Updating Your Laravel Configuration

Once you have your App Password, update your .env file in the Laravel project root. You need to modify the MAIL_PASSWORD variable to reflect the newly generated credential rather than your standard email password.

# .env file
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-16-character-app-password-here
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="your-email@gmail.com"
MAIL_FROM_NAME="${APP_NAME}"

In this configuration, MAIL_PORT is set to 587, which uses TLS encryption. This is the standard port for Gmail SMTP. If you prefer SSL, you can switch to port 465, but TLS on 587 is generally preferred for its flexibility with modern libraries. Ensure that MAIL_ENCRYPTION is set to tls to match the protocol requirements enforced by Google's servers.

Handling Localhost Development Environments

A common friction point arises when developers attempt to run these configurations strictly on localhost without proper environment handling. If you are testing locally and your mail server (e.g., Mailpit or a local SMTP relay) is distinct from Gmail, ensure you are pointing to the correct host in your .env file.

If you are indeed connecting directly to smtp.gmail.com from a local machine, verify that your operating system's firewall allows outbound connections on port 587. Additionally, some corporate or public networks block access to Gmail's IP ranges; if you face intermittent connection timeouts, consider testing the SMTP connection via a tool like telnet or openssl s_client to isolate whether the issue is network-level blocking or an authentication failure.

Migrating to OAuth 2.0 (Optional but Recommended)

While App Passwords resolve the immediate issue, Google's long-term roadmap suggests moving toward OAuth 2.0 for programmatic access. Laravel provides a robust implementation of this via packages like laravel/legacy-api-token or third-party libraries that handle the OAuth flow seamlessly. However, setting up OAuth requires registering an API project in the Google Cloud Console and installing the client library, which adds complexity to the setup process.

For many projects, especially those running on localhost or smaller-scale applications, App Passwords provide a sufficient bridge until a full migration is feasible. The trade-off is that App Passwords are static credentials; if compromised, they must be revoked and regenerated immediately. OAuth tokens, conversely, can be scoped to specific permissions and refreshed automatically, offering a more secure architecture for production environments.

Troubleshooting Common Pitfalls

If you have updated your credentials but emails still fail, check the MAIL_ENCRYPTION setting. Using ssl with port 587 will cause a handshake failure because those ports are reserved for TLS. Conversely, using tls with port 465 is also incorrect; that combination expects SSL encryption at the TCP layer.

Another frequent mistake involves using the wrong username. The MAIL_USERNAME must be your full email address (e.g., name@gmail.com), not just the username portion before the @. If you encounter an error message regarding "Less Secure Apps" persisting after these changes, it is likely a cached DNS record or a browser cache issue if accessing via a webmail interface, but for server-side SMTP connections in Laravel, the .env file is the source of truth. Ensure you are running php artisan config:clear after modifying your environment variables to ensure the application picks up the new SMTP credentials immediately.

Our network