Trying to receive attachments by email

Hi everyone

I’m trying to receive attachments by email

I tried following this doc

@anvil.email.handle_message
def handle_incoming_email(msg):
  print("printing attachments:")
  print(msg.attachments)
  for a in msg.attachments:
    print(a) 

Clone link:
share a copy of your app

PS I tried adding the attachments to a data Table but that didn’t work either

Hi @Steve2,

I think we’re going to need a bit more information in order to help you. Specifically:

…and then what happened next? You’ve provided plausible-looking sample code and a clone link, but in order for us to help with your problem we’re going to need to know what problem you’re seeing!

1 Like

Hi, in case it’s the same issue I had recently (that there are more inline attachments coming in than normal attachments) this is a snapshot of the code I used:

Process regular attachments

for a in msg.attachments:
app_tables.received_attachments.add_row(
date=email_date,
from_addr=msg.envelope.from_address,
subject=msg.subject,
attachment=a
)

Process inline attachments

for key, value in msg.inline_attachments.items():
app_tables.received_attachments.add_row(
date=email_date,
from_addr=msg.envelope.from_address,
subject=msg.subject,
attachment=value
)

Thanks,
Dave

Hi sry right

It’s printing an empty list no matter how many attachments I send(non-inline) and no matter what type attacghments(PNG, MP4, MP3, PDF) etc

Example Output:
printing attachments: