Skip to content

Commit

Permalink
Add email gateway.
Browse files Browse the repository at this point in the history
  • Loading branch information
amh-mw committed Dec 17, 2024
1 parent 34bf758 commit 0a84666
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions email_gateway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Inspired by https://github.com/odoo/odoo/blob/15.0/addons/mail/static/scripts/odoo-mailgate.py

import logging
import os
import xmlrpc.client

import boto3

from lambdoo import execute, make_response

_logger = logging.getLogger(__name__)

s3 = boto3.client('s3')


@make_response
def email_gateway(event, context):
bucket = os.environ['BUCKET']
key_prefix = os.environ['KEY_PREFIX']
for record in event['Records']:
key = record['ses']['mail']['messageId']
if key_prefix:
key = f"{key_prefix}/{key}"
_logger.info("processing email s3://%s/%s", bucket, key)
msg = s3.get_object(Bucket=bucket, Key=key)['Body'].read()
execute('mail.thread', 'message_process', [False, xmlrpc.client.Binary(msg)], {})

0 comments on commit 0a84666

Please sign in to comment.