How to Send an Email with an Attachment in Python - PythonAlgos
pythonalgos.com › how-to-send-an-email-with-anNov 02, 2021 · # locate and attach desired attachments att_name = os.path.basename(filename) _f = open(filename, 'rb') att = MIMEApplication(_f.read(), _subtype="txt") _f.close() att.add_header('Content-Disposition', 'attachment', filename=att_name) message.attach(att) # setup email server server = smtplib.SMTP_SSL(host, port) server.login(user, gmail_pass) # send email and quit server server.sendmail(user, to, message.as_string()) server.quit()