how can I get a s3 zip file and attached it in my email using boto3?

Viewed 13

I'm trying to get a zip file from my s3 bucket and then attached it in my email using boto3. I tried this but it doesn't work :


                msg = MIMEMultipart()
                def get_object(bucket,key):
                    client = boto3.client("s3")
                    return client.get_object(Bucket=bucket, Key=key)
                file =  get_object(BUCKET,key)
                from email import encoders
                from email.mime.base import MIMEBase

                msg_1 = MIMEBase('application')
                msg_1.set_payload(file['Body'].read())
                encoders.encode_base64(msg_1)
                msg_1.add_header('Content-Disposition', 'attachment', 
                            filename='file.zip')
                msg.attach(msg_1)
0 Answers
Related