moved
This commit is contained in:
53
email-worker/aws/ses_handler.py
Normal file
53
email-worker/aws/ses_handler.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
SES operations handler
|
||||
"""
|
||||
|
||||
import boto3
|
||||
from botocore.exceptions import ClientError
|
||||
|
||||
from logger import log
|
||||
from config import config
|
||||
|
||||
|
||||
class SESHandler:
|
||||
"""Handles all SES operations"""
|
||||
|
||||
def __init__(self):
|
||||
self.client = boto3.client('ses', region_name=config.aws_region)
|
||||
|
||||
def send_raw_email(
|
||||
self,
|
||||
source: str,
|
||||
destination: str,
|
||||
raw_message: bytes,
|
||||
worker_name: str
|
||||
) -> bool:
|
||||
"""
|
||||
Send raw email via SES
|
||||
|
||||
Args:
|
||||
source: From address
|
||||
destination: To address
|
||||
raw_message: Raw MIME message bytes
|
||||
worker_name: Worker name for logging
|
||||
|
||||
Returns:
|
||||
True if sent successfully, False otherwise
|
||||
"""
|
||||
try:
|
||||
self.client.send_raw_email(
|
||||
Source=source,
|
||||
Destinations=[destination],
|
||||
RawMessage={'Data': raw_message}
|
||||
)
|
||||
return True
|
||||
|
||||
except ClientError as e:
|
||||
error_code = e.response['Error']['Code']
|
||||
log(f"⚠ SES send failed to {destination} ({error_code}): {e}", 'ERROR', worker_name)
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
log(f"⚠ SES send failed to {destination}: {e}", 'ERROR', worker_name)
|
||||
return False
|
||||
Reference in New Issue
Block a user