Skip to content Skip to sidebar Skip to footer

Send Email With Gmail Python

I am attempting to send an email, but I run into this error: smtplib.SMTPAuthenticationError: (534, b'5.7.9 Application-specific password required. Learn more at\n5.7.9 https://su

Solution 1:

I tried my best... I think this should work!

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

email = "test@gmail.com"# the email where you sent the email
password = "yourPassword"
send_to_email = "yourEmail@gmail.com"# for whom
subject = "Gmail"
message = "This is a test email sent by Python. Isn't that cool?!"

msg = MIMEMultipart()
msg["From"] = email
msg["To"] = send_to_email
msg["Subject"] = subject

msg.attach(MIMEText(message, 'plain'))

server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(email, password)
text = msg.as_string()
server.sendmail(email, send_to_email, text)
server.quit()

Solution 2:

You must allow the "Less secure apps" in Google configurations.

Here is the link of another thread about it : Link

Post a Comment for "Send Email With Gmail Python"