Expected response code 250 but got code "535", with message "535-5.7.8 Username and Password not accepted

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Troubleshooting SwiftMailer's Error Code 535: "Username and Password not accepted" Introduction: It is no secret that the process of sending emails can sometimes be a challenging task for developers, especially when working with services like Gmail. As users, we often face various issues while sending mails, such as the one discussed here related to SwiftMailer's error code 535. This blog post aims at providing a comprehensive understanding of this issue and offering solutions for dealing with it effectively. 1. Understanding the Error Code: The error code 535, along with the message "Username and Password not accepted", is usually thrown by SwiftMailer when sending mail through Gmail or any other SMTP service. This error indicates that the credentials provided in the configuration are incorrectly set or have been rejected by the server. 2. Checking the Credentials: The first step towards fixing this issue should be double-checking the credentials you have provided for the SMTP connection. Ensure that your mail driver, mail host, port, username, and password are correct in the configuration file. If you've recently changed them or have forgotten your new details, update them accordingly. 3. Using Appropriate SMTP Ports: For Gmail, the default port for SMTP connection is 465 for secure connections over SSL (TLS) and 25 for non-secure, plain text connections. However, it is advisable to use port 587 as this is a more secure option, explicitly designed for sending emails using TLS encryption. 4. Enabling Less Secure Apps: Google has implemented an additional security feature called "Less Secure Apps". This feature blocks access from applications that are not explicitly authorized by the user to connect to their account. It can lead to this error code if it is disabled by your Gmail account settings. To enable it, follow these steps: - Log in to your Google Account. - Go to https://myaccount.google.com/lesssecureapps. - Turn on the "Allow less secure apps" option and save changes. 5. Checking Mailbox for Spam Alerts: If you are still experiencing this error despite following all the above steps, check your Gmail account for any spam alerts or security notifications. Google might have suspected unusual activity from your app due to sending a high volume of emails in a short time and blocked your access temporarily. In such cases, it is necessary to verify the authenticity of your email address by following the instructions provided in the alert. 6. Using Authentication Methods: You can also set up different authentication methods such as OAuth or Application-specific passwords within Gmail. These options allow better control and security over who can access your account while ensuring that you can continue sending emails from your application without any issues. 7. Optimizing Code for Efficient Email Sending: If you are experiencing this issue due to a high volume of email sends, consider optimizing your code. Implement throttling mechanisms to limit the number of concurrent connections and avoid spam triggers. Ensure that your mail queue processing is efficient and doesn't overwhelm your application server by limiting parallel connections. 8. Conclusion: By following these methods, you can successfully troubleshoot SwiftMailer error code 535 and continue to send emails efficiently. Remember that using secure authentication methods and optimizing your email sending code greatly reduces the chances of encountering similar errors. In case you're still facing issues, don't hesitate to reach out for help through forums or professional support resources such as Laravel Company's extensive tutorials and guides.