Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google appengine Send local gif as an email attachment

I'm trying to send a local gif as an email attachment on Google appengine. The email will send but without an attachment.

message = mail.EmailMessage(sender="My image <[email protected]>",
subject="image")

message.to = "Jim <[email protected]>"

message.body = my_body_text

message.html = my_body_html

image = open('./bust.gif', 'r')

attachments=[(image.name, image.read())]

message.send()

image.close()
like image 236
Jim Avatar asked Jan 20 '23 02:01

Jim


1 Answers

You forgot to set the attachments field on your message, and made a local variable you didn't use instead. Simply change

attachments=[(image.name, image.read())]

to

message.attachments=[(image.name, image.read())]
like image 176
Sebastian Paaske Tørholm Avatar answered Jan 30 '23 00:01

Sebastian Paaske Tørholm