changes
This commit is contained in:
@@ -107,7 +107,8 @@ def _month_bucket(ts_iso):
|
||||
|
||||
|
||||
def write_event_row(*, event_type, source, recipients, message_id, timestamp_iso,
|
||||
size_bytes=None, subject=None, bounce_type=None, complaint_type=None):
|
||||
size_bytes=None, subject=None, bounce_type=None, complaint_type=None,
|
||||
smtp_response=None, reporting_mta=None):
|
||||
"""
|
||||
Write a row to the unified ses-events table.
|
||||
|
||||
@@ -143,6 +144,10 @@ def write_event_row(*, event_type, source, recipients, message_id, timestamp_iso
|
||||
item['bounce_type'] = bounce_type
|
||||
if complaint_type:
|
||||
item['complaint_type'] = complaint_type
|
||||
if smtp_response:
|
||||
item['smtp_response'] = smtp_response[:500]
|
||||
if reporting_mta:
|
||||
item['reporting_mta'] = reporting_mta
|
||||
|
||||
events_table.put_item(Item=item)
|
||||
print(f"ses-events <- {event_type} {pk} {sk}")
|
||||
@@ -256,6 +261,32 @@ def handle_complaint(detail):
|
||||
complaint_type=complaint_type,
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# New: delivery handler
|
||||
# ------------------------------------------------------------
|
||||
def handle_delivery(detail):
|
||||
delivery = detail.get('delivery', {}) or {}
|
||||
mail = detail.get('mail', {}) or {}
|
||||
|
||||
source = mail.get('source')
|
||||
message_id = mail.get('messageId')
|
||||
timestamp = delivery.get('timestamp') or mail.get('timestamp') or datetime.now(timezone.utc).isoformat()
|
||||
recipients = delivery.get('recipients') or []
|
||||
smtp_response = delivery.get('smtpResponse') # wörtliche M365-Antwort
|
||||
reporting_mta = delivery.get('reportingMTA')
|
||||
processing_ms = delivery.get('processingTimeMillis')
|
||||
|
||||
print(f"Delivery: id={message_id} to={recipients} smtp={smtp_response!r} mta={reporting_mta}")
|
||||
|
||||
write_event_row(
|
||||
event_type='delivery',
|
||||
source=source,
|
||||
recipients=recipients,
|
||||
message_id=message_id,
|
||||
timestamp_iso=timestamp,
|
||||
smtp_response=smtp_response,
|
||||
reporting_mta=reporting_mta,
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# Entry point
|
||||
@@ -274,6 +305,8 @@ def lambda_handler(event, context):
|
||||
handle_send(detail)
|
||||
elif event_type == 'Email Complaint Received':
|
||||
handle_complaint(detail)
|
||||
elif event_type == 'Email Delivered':
|
||||
handle_delivery(detail)
|
||||
else:
|
||||
print(f"Ignoring event type: {event_type}")
|
||||
except Exception as exc:
|
||||
|
||||
Reference in New Issue
Block a user