import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
email_user = '[email protected]'
email_send = '[email protected]'
subject = 'Python'
msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = email_send
msg['Subject'] = subject
body = "HI"
msg.attach(MIMEText(body, 'plain'))
filename = 'caminho_para_arquivo\\Documentos.xlsx'
attachment = open(filename, 'rb')
part = MIMEBase('application', 'octet-stream')
attachment = base64.b64encode(bytes(attachment, 'utf-8'))
part.set_payload((attachment).read)
encoders.encode_base64(part)
part.add_header('Content-Disposition',"attachament; filename="+filename)
msg.attach(part)
text = msg.as_string()
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(email_user, 'xxxxxx')
server.sendmail(email_user, email_send, text)
server.quit()
Estou recebendo o erro de:
TypeError: encoding without a string argument
Gostaria de saber se é possível enviar planilha ou qualquer outra extensão do excel.