I just want to send an email in python with an attachment
import smtplib, os
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
fr
On gmail you also have to give a smtp.ehlo()
before smtp.starttls()
This is also duplicate of How to send an email with Gmail as provider using Python?
You need a call to starttls()
before you login:
smtp = smtplib.SMTP('smtp.gmail.com:587')
smtp.starttls()
smtp.login('fu@gmail.com', 'fu')
Also, your send_from
should be a str
, not a list
:
send_from='fu@gmail.com'
Note that smtp.starttls()
calls smtp.ehlo()
implicitly:
If there has been no previous EHLO or HELO command this session, this method tries ESMTP EHLO first. https://docs.python.org/2/library/smtplib.html#smtplib.SMTP.starttls