2026-07-15

Gmail smtp SASL authentication

Stefan Bogdanescu

Stefan Bogdanescu

Founder & Senior Architect

Gmail smtp SASL authentication

Decoding Gmail SMTP SASL Authentication Failures in Postfix

As senior developers, we often deal with the complexities of infrastructure and external service integrations. Sending email reliably using protocols like SMTP involves layers of security, authentication (SASL), and transport encryption (TLS). When setting up a mail relay like Postfix to connect to a service like Gmail, unexpected authentication failures are common.

The specific error you are encountering—delivery temporarily suspended: SASL authentication failed; server smtp.gmail.com said: 534-5.7.14—is a clear signal that the connection was established, but the credentials provided for the SASL challenge were rejected by the mail server (Gmail). This issue is rarely about incorrect Postfix syntax alone; it usually stems from how Google handles modern security protocols like Two-Factor Authentication (2FA) and application password usage.

Let's dive deep into why this happens and how to resolve it, focusing on best practices for secure email delivery.

Understanding the SASL Challenge with Gmail

SASL (Simple Authentication and Security Layer) is the framework used to secure the communication channel between your mail server (Postfix) and the SMTP server (Gmail). When you configure Postfix to use an external relay via SMTP, it must present valid credentials for authentication.

The reason you are seeing this specific error often relates to Google's security policies:

  1. Two-Factor Authentication (2FA): If you have 2FA enabled on your Google account, standard account passwords alone are insufficient for sending mail via external SMTP relays.
  2. Application Passwords: For applications (like Postfix) to securely connect, you must use specific "App Passwords" generated within your Google security settings, rather than your main account password. These are designed specifically for third-party application access and bypass standard 2FA restrictions on the main login.

Reviewing Your Postfix Configuration

Your provided configuration is fundamentally sound for setting up basic SASL relay:

# /etc/mailname (main.cf) snippet
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd

The setup correctly instructs Postfix to use a password map to look up the credentials for smtp.gmail.com:587. The issue is almost certainly not in this configuration structure itself, but in the content of the password used within that map.

The Solution: Focus on Google Account Security

The fix lies outside the Postfix configuration and within your Google account settings.

Step 1: Generate an App Password

You must ensure you are using a specific, restricted password generated by Google for this purpose.

  1. Log into your Google Account security settings.
  2. Navigate to the App Passwords section (this is often hidden behind the main security panel).
  3. Generate a new password specifically for an "Mail" application. This will be a unique, long string that you use in place of your regular login password in your sasl_passwd file.

Step 2: Update the Password Map

Replace the standard password in your /etc/postfix/sasl/sasl_passwd file with the newly generated App Password:

# /etc/postfix/sasl/sasl_passwd
[smtp.gmail.com]:587 YOUR_GENERATED_APP_PASSWORD

After saving this file, remember to update Postfix's cache by running:

sudo postmap /etc/postfix/sasl_passwd
sudo systemctl restart postfix

Best Practices for Application Email Sending

When building modern applications—especially those using PHP frameworks like Laravel—relying solely on direct SMTP relay can introduce security risks. For robust, scalable email handling, consider leveraging dedicated services or library integrations rather than raw Postfix configuration for every request. Frameworks often provide better abstraction layers for managing these complex connections securely. For example, when setting up services that require robust external communication and authentication, understanding how to manage secrets is paramount, much like in secure Laravel service providers.

Conclusion

The error you faced was a classic symptom of modern email security protocols clashing with standard password usage. By switching from your main account password to a specific App Password provided by Google, you satisfy the SASL authentication requirements without compromising your primary account security. Always prioritize generating application-specific credentials when dealing with external services. Ensure all configurations are rigorously tested, and for complex infrastructure like this, leveraging well-tested architectural patterns is always recommended.

Note: Blog content is currently available in English.

Tags:

Enhance your marketing setup with your own email marketing platform.

Join the growing number of SaaS platforms using Laravel Mail to offer email marketing solutions to their customers.