Configuring flask and testing was quick and easy but sending attachment is very difficult if not impossible. Does anyone have a tip or example to send attachments with Flask-Mail?
My code looks like this:
mail = Mail(app)
MAIL_CONFIG = app.config
msg = Message(
assunto,
sender = (MAIL_CONFIG['MAIL_NAME'], MAIL_CONFIG['MAIL_USERNAME']),
reply_to = MAIL_CONFIG['MAIL_NAME'] + '<' + MAIL_CONFIG['MAIL_USERNAME'] + '>',
recipients = destinatarios
)
msg.body = texto
msg.html = mensagem
# arquivo = 'downloads/bbbb.txt'
# with app.open_resource(arquivo) as fp:
# msg.attach(arquivo, "text/plain", fp.read())
mail.send(msg)
If I uncomment the commented lines I get the following error:
TypeError: normalize () argument 2 must be unicode, not str