Python 使用Flask发送Postgre中保存的带有附件的邮件-使用邮枪
我使用以下代码发送电子邮件Python 使用Flask发送Postgre中保存的带有附件的邮件-使用邮枪,python,postgresql,flask,mailgun,Python,Postgresql,Flask,Mailgun,我使用以下代码发送电子邮件 但我需要知道如何发送存储在Postgre数据库中的文件(PDF或JPG)。请以文本形式而不是图像形式提供代码。屏幕阅读器无法读取图像中的文本,无法搜索。 comprobantes = Documentacion.query.filter_by( referencia=referencia2, notificacion="Comprobante").all() listacomprobant
但我需要知道如何发送存储在Postgre数据库中的文件(PDF或JPG)。请以文本形式而不是图像形式提供代码。屏幕阅读器无法读取图像中的文本,无法搜索。
comprobantes = Documentacion.query.filter_by(
referencia=referencia2, notificacion="Comprobante").all()
listacomprobantes = []
listacomprobantes2 = []
#print (listacomprobantes)
for x in comprobantes:
print(x.nombre)
data = BytesIO(x.img)
encoded_img_data = base64.b64encode(data.getvalue())
image = encoded_img_data.decode('utf-8')
requests.post(
"https://api.mailgun.net/v3/***s",
auth=("api", "****"),
#files=[("attachment", ("prueba.pdf", open("prueba.pdf", "rb").read()))],
data={"from": "****@gmail.com",
"to": [para],
"subject": titulocorreo1,
"html": html,
})