Skip to main content

Receiving Emails

You can trigger a hook by sending an email to the email address associated with the hook: [subdomain]+[hook-path]@abstra-notifications.com.

The email is received as a request, and the body, subject, sender, and recipient are printed. The attachments are decoded and saved to a persistent directory.

import abstra.hooks as ah
from abstra.common import get_persistent_dir
import base64
from abstra.tasks import send_task

email = ah.get_email_request()

print("⚙️ Hook is running... received email:")

# Print email details
print("📧 Body:", email.body)
print("📧 Subject:", email.subject)
print("📧 From:", email.from_)
print("📧 To:", email.to)

# Save attachments to persistent directory
for atx in email.attachments:
file_name = atx.get('filename')
file_data = atx.get('payload')
decoded_data = base64.b64decode(file_data)

nota_fiscal = get_persistent_dir() / file_name
with open(nota_fiscal, 'wb') as f:
f.write(decoded_data)