Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

python - Send mail with attachments saved in Postgre with Flask - using Mailgun

I am using the following code to send emails

enter image description here

But I need to know how to send files (PDF or JPG) stored in Postgre database.

question from:https://stackoverflow.com/questions/65865088/send-mail-with-attachments-saved-in-postgre-with-flask-using-mailgun

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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,
                      })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...