What I’m trying to do:
I’m trying to display and save email attachments but the code only replies to my email and does not print or save any attachments I send. Could there be a glitch in my setup?
Code Sample:
@anvil.email.handle_message()
def message_handler(msg):
for attachment in msg.attachments:
app_tables.received_files.add_row(file=attachment, frm=msg.envelope.sender)
print ("attachment: " + attachment)
msg.reply(text="Received")
EDIT: I updated the code so it should send back any attachments received, to help test:
@anvil.email.handle_message
def message_handler(msg):
for att in msg.attachments:
print ("attachment: " + att.name)
app_tables.received_files.add_row(file=att)
anvil.email.send(to=msg.envelope.from_address, from_name='hi', subject='returning', text='test', attachments=[anvil.BlobMedia(att.content_type, att.get_bytes(), name=att.name) for att in msg.attachments])