shape
shape
shape
shape
shape

Set Up a Custom Email with Your Domain Using Amazon SES, S3, and Lambda

Set Up a Custom Email with Your Domain Using Amazon SES, S3, and Lambda

From edge computing to sustainability—cloud is evolving fast.

📧 Set Up a Custom Email with Your Domain Using Amazon SES, S3, and Lambda

Part 1: Receive Emails Using Amazon SES + S3

What You'll Need

  • A domain name (e.g., abc123.com) configured in Route 53
  • Access to AWS Console: SES, S3, Route 53

Step 1: Verify Domain in SES

  1. Go to Amazon SES → Verified identities
  2. Click Create identity, select Domain, and enter your domain
  3. Use Route 53 to auto-add DNS records or manually add TXT/DKIM if using another provider
  4. Wait for domain to show as Verified

Step 2: Create S3 Bucket to Store Emails

  1. Go to S3 → Create bucket
  2. Name it something like abc123-emails
  3. Disable public access and enable encryption

Step 3: Set MX Record in Route 53

  1. Go to Route 53 → Hosted Zones → abc123.com
  2. Create MX record:
    10 inbound-smtp.us-east-1.amazonaws.com

Step 4: Create Email Receiving Rule in SES

  1. Go to SES → Email Receiving → Rule Sets
  2. If no rule set exists, create one and activate it
  3. Click Create rule:
    • Recipient: me@abc123.com or @abc123.com
    • Action: S3 → Choose your bucket

Part 2: Forward Emails Using Lambda and Send via SES SMTP

Step 1: Create IAM Role for Lambda

  1. Go to IAM → Roles → Create role
  2. Select service: Lambda
  3. Attach policies:
    AmazonS3ReadOnlyAccess, AmazonSESFullAccess, AWSLambdaBasicExecutionRole

Step 2: Create Lambda Function

  1. Go to Lambda → Create function
  2. Use Python 3.12 and assign the role created above
  3. Paste this code:
  4. import boto3
    import email
    import os
    
    s3 = boto3.client('s3')
    ses = boto3.client('ses')
    
    FORWARD_TO = "your@gmail.com"
    
    def lambda_handler(event, context):
        record = event['Records'][0]
        bucket = record['s3']['bucket']['name']
        key = record['s3']['object']['key']
        response = s3.get_object(Bucket=bucket, Key=key)
        raw_email = response['Body'].read()
        ses.send_raw_email(
            Source=FORWARD_TO,
            Destinations=[FORWARD_TO],
            RawMessage={'Data': raw_email}
        )
        return {'status': 'Email forwarded'}

Step 3: Add S3 Trigger

  1. In the Lambda function, add S3 trigger for the email bucket
  2. Set event type: Object Created
  3. Prefix (optional): inbox/

Step 4: Send Emails Using SES SMTP

  1. Go to SES → SMTP settings → Create SMTP credentials
  2. Use these settings in your mail client:
    • SMTP: email-smtp.us-east-1.amazonaws.com
    • Port: 587
    • Username/Password: from SES

Step 5: Improve Deliverability

  1. Enable DKIM signing under SES → Domains
  2. Add SPF record to Route 53:
    "v=spf1 include:amazonses.com -all"

🎉 Done!

Your email setup is now live using your domain name, all managed serverlessly with Amazon SES, S3, and Lambda!