I’m experiencing a challenging SMTP authentication issue while attempting to send emails via Gmail using Python on a cloud-based service. This error has cropped up recently, even though my code has been functioning properly for months.
The specific error message I receive is:
SMTPAuthenticationError: (534, '5.7.14 Please sign in through your web browser and then try again')
Here’s a portion of my code that’s used for sending emails:
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
company_name = 'hamburger heaven'
deal_type = 'consultation'
analyzer = 'John'
item_id = '12345678'
sales_rep = 'alice smith'
website_link = 'link to company website'
analyzer_firstname = analyzer.split(' ')[0]
sales_rep_firstname = sales_rep.split(' ')[0]
contact_email = '[email protected]'
analyzer_email = '[email protected]'
email_pass = 'securepassword'
email_message = MIMEMultipart()
email_message['From'] = analyzer
email_message['To'] = contact_email
email_message['Subject'] = f'Introduction to {company_name} - {deal_type} onboarding'
email_body = f'Thank you {sales_rep_firstname},\n\nHi {analyzer_firstname},\n\nWe are happy to collaborate with you. To begin our onboarding process, please visit this link (link to onboarding {website_link}/{item_id}). If you have any questions while preparing the required documents, don't hesitate to reach out to me.'
email_message.attach(MIMEText(email_body, 'plain'))
smtp_server = smtplib.SMTP('smtp.gmail.com', 587)
smtp_server.ehlo()
smtp_server.starttls()
smtp_server.login(analyzer_email, email_pass)
smtp_server.sendmail(analyzer_email, contact_email, email_message.as_string())
smtp_server.quit()
I’ve ensured that less secure apps are permitted in my Gmail settings, but the issue continues. Has anybody else faced this authentication problem lately? Any help in resolving it would be greatly appreciated.