Script to forward encrypted messages stored in S3 buckets by SES as attachments via SES.
I wrote this because I have a bunch of domains where I don't actively use email, but also don't want to bounce everything. This script allows me to schedule a cron job that runs once a day and sends me all emails that arrived on catchall accounts for these domains as attachments for simple review.
# composer require aws/aws-sdk-php phpmailer/phpmailer
ses:SendRawEmail
s3:DeleteObject
s3:GetObject
s3:ListBucket
s3:ListAllMyBuckets
kms:Decrypt
Modify the following variables to your own:
$kmsKeyId // This is ID of KMS key SES uses to encrypt messages stored in S3
$mail->setFrom("[email protected]", "S3 Mailer") // From address and subject for summary emails
$mail->addAddress("[email protected]") // Address where you want to receive summary emails
You will also need to set region for various AWS clients to match your own
I use EC2 roles for access to all required AWS services. You can also configure authentication inside PHP if you're not running this on EC2 instance.