You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS SES自定义域名邮箱配置求助:新手遇验证及Gmail转发问题

Solution: Verify Your Custom SES Emails & Set Up Forwarding to Gmail

Hey there! I totally get how overwhelming AWS SES can feel when you’re just starting out—all those menus and settings can make your head spin. Let’s break this down into simple, actionable steps to get your custom email addresses (like mynameis@michaldang.cz) working and forwarding to your Gmail.

Part 1: Verifying Your Custom Email Addresses (For Sending Emails)

Since you’ve already verified your entire domain (michaldang.cz) in SES, you can technically send emails from any address under that domain without verifying each one individually. But if you want to confirm ownership of specific addresses (or if SES prompts you to verify them), here’s how:

  1. Open the SES Management Console and navigate to Identity Management > Email Addresses.
  2. Click the Verify a New Email Address button.
  3. Type in the full email address you want to use (e.g., mynameis@michaldang.cz) and hit Verify This Email Address.
  4. Hold off on clicking the verification link for now—we need to set up forwarding first so that verification email lands in your Gmail. Let’s tackle that next.

Part 2: Setting Up Email Forwarding to Gmail

SES doesn’t have built-in forwarding, but we can use a combo of S3 (to store incoming emails) and Lambda (to forward them to Gmail) to make this work. Let’s go step by step:

Step 1: Create an S3 Bucket to Store Incoming Emails

  • Head to the S3 Console and click Create bucket.
  • Pick a unique name (like michaldang-ses-incoming-emails—bucket names are global, so it has to be one-of-a-kind).
  • Leave the default settings for region and permissions, then click Create bucket.
  • Once the bucket is created, go to its Permissions tab, then Bucket Policy.
  • Paste this policy, replacing BUCKET_NAME with your bucket’s name, YOUR_AWS_ACCOUNT_ID with your 12-digit AWS account ID, and michaldang.cz with your domain:
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "ses.amazonaws.com"
      },
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::BUCKET_NAME/*",
      "Condition": {
        "StringEquals": {
          "aws:Referer": "YOUR_AWS_ACCOUNT_ID"
        },
        "StringLike": {
          "s3:prefix": "emails/*"
        }
      }
    }
  ]
}
  • Save the policy.

Step 2: Create a Lambda Function to Forward Emails to Gmail

  • Go to the Lambda Console and click Create function.
  • Choose Author from scratch.
  • Name it something like SESForwardToGmail, select Python 3.11 (or the latest available Python runtime), then click Create function.
  • In the Code tab, replace the default code with this script (make sure to swap YOUR_GMAIL_ADDRESS with your actual Gmail, and SENDER_EMAIL with one of your custom domain addresses like mynameis@michaldang.cz):
import boto3
import email
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

def lambda_handler(event, context):
    s3 = boto3.client('s3')
    ses = boto3.client('ses')

    # Fetch the incoming email from S3
    bucket = event['Records'][0]['s3']['bucket']['name']
    key = event['Records'][0]['s3']['object']['key']
    response = s3.get_object(Bucket=bucket, Key=key)
    raw_email = response['Body'].read()

    # Parse the original email
    msg = email.message_from_bytes(raw_email)
    subject = msg['Subject'] or "No Subject"
    sender = msg['From']

    # Create a new email to forward to Gmail
    forward_msg = MIMEMultipart()
    forward_msg['Subject'] = f"FWD: {subject}"
    forward_msg['From'] = "SENDER_EMAIL"
    forward_msg['To'] = "YOUR_GMAIL_ADDRESS"

    # Add the original email content as a plain text part
    if msg.is_multipart():
        for part in msg.walk():
            if part.get_content_type() == 'text/plain':
                body = part.get_payload(decode=True).decode('utf-8')
                forward_msg.attach(MIMEText(body, 'plain'))
    else:
        body = msg.get_payload(decode=True).decode('utf-8')
        forward_msg.attach(MIMEText(body, 'plain'))

    # Send the forwarded email via SES
    try:
        ses.send_raw_email(
            Source="SENDER_EMAIL",
            Destinations=["YOUR_GMAIL_ADDRESS"],
            RawMessage={'Data': forward_msg.as_string()}
        )
        return {'statusCode': 200, 'body': 'Email forwarded successfully'}
    except Exception as e:
        print(f"Error forwarding email: {e}")
        return {'statusCode': 500, 'body': str(e)}
  • Save the code.
  • Now, give Lambda permissions to access S3 and SES:
    • Go to the Configuration tab of your Lambda function, then Permissions.
    • Click the execution role link (it’ll look like SESForwardToGmail-role-xxxx).
    • In the IAM Console, click Add permissions > Attach policies.
    • Search for and attach AmazonS3ReadOnlyAccess (more secure than full access) and AmazonSESFullAccess.
    • Save the changes.

Step 3: Set Up SES Receipt Rules to Route Emails

  • Back in the SES Management Console, go to Email Receiving > Receipt Rules.
  • If you don’t have a rule set yet, click Create Rule Set, then Create Rule.
  • Under Recipients, enter your custom email address (e.g., mynameis@michaldang.cz) or leave it blank to forward all emails sent to your domain.
  • Click Next.
  • Add two actions:
    1. Add action > S3: Select your S3 bucket, set the prefix to emails/, then click Save.
    2. Add action > Lambda: Select your Lambda function from the dropdown, then click Save.
  • Click Next, review your rule, then click Create Rule.

Step 4: Update Your Domain’s DNS Records

To make sure emails sent to your custom address reach SES, add an MX record to your domain’s DNS settings:

  • The MX record’s value should be inbound-smtp.YOUR_REGION.amazonaws.com (replace YOUR_REGION with the AWS region you’re using for SES, like us-east-1).
  • Set the priority to 10 (this tells mail servers which server to use first).

Final Step: Verify Your Email Address

Now that forwarding is set up, go back to Identity Management > Email Addresses in SES. If you didn’t get the verification email yet, click Resend Verification Email. You’ll receive it in your Gmail inbox—click the verification link, and you’re done!

From now on, any emails sent to your custom domain addresses will be forwarded straight to your Gmail, and you can send emails from those addresses using SES. If Gmail marks the forwarded emails as spam, just add your custom address to your Gmail contacts to fix that.

内容的提问来源于stack exchange,提问作者Michal Dang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:59:14