If you’re running a multi-account AWS setup, you might need one account to send emails through SES while the SMTP credentials live in another account’s Secrets Manager. This guide walks you through setting up cross-account Secrets Manager access for AWS SES: the resource policy, IAM permissions, and a working Python script.
How Cross-Account SES Email Works
Account A owns the SES domain and stores SMTP credentials in Secrets Manager. Account B runs the Lambda or script that sends the email. Instead of duplicating credentials, you grant Account B permission to read the secret from Account A.
This needs three coordinated permissions: a resource-based policy on the secret in Account A, and an IAM policy on Account B’s role that allows secretsmanager:GetSecretValue. The secret must use a customer-managed KMS key, with a key policy permitting Account B’s role to decrypt and a matching kms:Decrypt identity permission. The AWS-managed aws/secretsmanager key cannot be used for cross-account reads. For a deeper look at the general pattern, see How to Access AWS Secrets Manager from Another Account.
Prerequisites
- Two AWS accounts: Account A (SES + Secrets Manager) and Account B (runs the email code)
- A verified SES domain or email address in Account A
- SES SMTP credentials stored in Secrets Manager (Account A)
- AWS CLI configured: see How to Install AWS CLI v2 on Ubuntu 22.04 if needed
- A Lambda function or Python environment in Account B with
boto3
Step 1: Add a Resource Policy to the Secret in Account A
In Secrets Manager (Account A), open the secret and attach this resource-based policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowCrossAccountSecretAccess",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::ACCOUNT_B_ID:role/your-lambda-execution-role"
},
"Action": "secretsmanager:GetSecretValue",
"Resource": "*"
}
]
}
Here’s what each field does:
Principal: the IAM role ARN from Account B that’s allowed to access the secret. ReplaceACCOUNT_B_IDwith Account B’s account ID andyour-lambda-execution-rolewith the actual role name.Action: only allowsGetSecretValue, which is the minimum permission needed to read the secret.Resource: set to*here, but you can tighten it by using the full secret ARN instead.
If your accounts are in an AWS Organization, you can also add an aws:PrincipalOrgID condition to restrict access to your org:
"Condition": {
"StringEquals": {
"aws:PrincipalOrgID": "o-your-org-id"
}
}
Step 2: Grant IAM Permissions in Account B
The resource policy alone isn’t enough. Account B’s Lambda role also needs an IAM policy that allows reading the secret:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "secretsmanager:GetSecretValue",
"Resource": "arn:aws:secretsmanager:us-east-1:ACCOUNT_A_ID:secret:your-ses-smtp-secret-AbCdEf"
},
{
"Effect": "Allow",
"Action": "kms:Decrypt",
"Resource": "arn:aws:kms:us-east-1:ACCOUNT_A_ID:key/YOUR_KEY_ID"
}
]
}
Replace ACCOUNT_A_ID, ACCOUNT_B_ID and YOUR_KEY_ID with your values. Copy the exact full secret ARN, including its generated six-character suffix, from Secrets Manager. AbCdEf is only an example suffix; no wildcard is required when you know the full ARN.
In Account A, create or select a customer-managed symmetric KMS key and configure the secret to use it. Add the following statement to the existing key policy; preserve its administrator and recovery permissions. Do not replace the whole key policy with this statement. See AWS’s cross-account secret procedure.
{
"Sid": "AllowAccountBSecretDecryption",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::ACCOUNT_B_ID:role/your-lambda-execution-role"
},
"Action": "kms:Decrypt",
"Resource": "*"
}
The secret resource policy, the KMS key policy, and Account B’s identity permissions must all allow access. Organization policies, permission boundaries and explicit denies can still block it.
Step 3: Python Script to Retrieve Credentials and Send Email
This script pulls SMTP credentials from Secrets Manager in Account A and sends an email through the SES SMTP endpoint:
import boto3
import json
import smtplib
import ssl
from email.mime.text import MIMEText
from botocore.exceptions import ClientError
AWS_REGION = "us-east-1"
SECRET_ARN = "arn:aws:secretsmanager:us-east-1:ACCOUNT_A_ID:secret:your-ses-smtp-secret-AbCdEf"
SENDER_EMAIL = "noreply@example.com"
RECIPIENT_EMAIL = "recipient@example.com"
def get_ses_credentials():
client = boto3.client("secretsmanager", region_name=AWS_REGION)
try:
response = client.get_secret_value(SecretId=SECRET_ARN)
secret = json.loads(response["SecretString"])
return {
"server": secret["SMTP_SERVER"],
"port": int(secret["SMTP_PORT"]),
"username": secret["SMTP_USERNAME"],
"password": secret["SMTP_PASSWORD"],
}
except ClientError as e:
print(f"Failed to retrieve secret: {e}")
raise
def send_email():
creds = get_ses_credentials()
msg = MIMEText("Hello from AWS SES via cross-account Secrets Manager!")
msg["Subject"] = "Test Email from Account B"
msg["From"] = SENDER_EMAIL
msg["To"] = RECIPIENT_EMAIL
with smtplib.SMTP(creds["server"], creds["port"], timeout=20) as server:
server.starttls(context=ssl.create_default_context())
server.login(creds["username"], creds["password"])
server.send_message(msg)
print("Email sent successfully.")
send_email()
Here’s what the key parts do:
boto3.client("secretsmanager"): creates a Secrets Manager client that uses Account B’s IAM role to make API calls.get_secret_value(SecretId=SECRET_ARN): retrieves the secret. Use the full ARN, not just the name: cross-account access requires the ARN.SENDER_EMAIL: must be a verified email or domain in SES (Account A). This is separate from the SMTP username.smtplib.SMTP(server, port): connects to the SES SMTP endpoint. The server is typicallyemail-smtp.us-east-1.amazonaws.comand port587is for STARTTLS.server.starttls(context=ssl.create_default_context()): upgrades the connection to TLS before sending credentials.
SES SMTP Credentials vs IAM Credentials
SES SMTP credentials are not the same as IAM access keys. When you create SMTP credentials in the SES console, AWS creates IAM-backed credentials; the SMTP username corresponds to the IAM access key ID and the password is derived for a specific Region, rather than being the raw AWS secret key. These go into Secrets Manager and are used with smtplib. Your IAM credentials are what boto3 uses to call the Secrets Manager API. So there are two layers here: IAM handles the secret retrieval, SMTP credentials handle the email sending.
For new applications, consider SES sending authorization so a delegate uses its own credentials for an approved identity, or assume a narrowly scoped role in the SES-owning account and call the SESv2 API with temporary credentials. SMTP does not accept passwords derived from temporary STS credentials. To rotate SMTP, regenerate credentials using AWS’s SMTP credential procedure, update Secrets Manager, test, then retire the old IAM credentials. Identity verification, sandbox status and sending quotas are regional.
Why Use This Pattern
- Single source of truth: credentials exist in one place. After rotating the IAM-backed SMTP credentials, update the secret and verify all clients refresh it; changing only the stored password does not rotate IAM credentials.
- Least privilege: Account B never stores credentials locally, only reads them at runtime.
- Auditing: CloudTrail in Account A logs every secret access.
- Scales easily: same pattern whether you have 2 accounts or 20.
This is the same trust model used for other cross-account resources. If you’ve done cross-account access with AssumeRole or copied S3 objects across accounts, you’ll recognize the pattern.
Troubleshooting
AccessDeniedException when retrieving the secret
Check the secret resource policy, customer-managed KMS key policy, and Account B’s identity policy, including kms:Decrypt on the exact key ARN. The default aws/secretsmanager key cannot decrypt cross-account. Also make sure you’re using the secret’s full ARN in SecretId, not just the name.
SMTP authentication failure
Confirm the SMTP credentials in Secrets Manager are correct and haven’t been rotated without updating the secret value. Also check that the sender email or domain is verified in SES. If SES is still in sandbox mode, you can only send to verified addresses.
Connection timeout on port 587
If your Lambda runs inside a VPC, it might not have internet access. You’ll need a NAT gateway or VPC endpoint for Secrets Manager, plus a route to SMTP. The SES SMTP interface endpoint service com.amazonaws.REGION.email-smtp can provide a private path on supported AZs; configure DNS and endpoint security-group access on port 587. Otherwise use a NAT path to the public SMTP endpoint. Lambda outside a VPC has internet access by default.
Conclusion
That covers sending email through AWS SES with SMTP credentials stored in another account’s Secrets Manager. The main thing to remember is that cross-account access requires policies on both sides: the secret resource policy, the calling role’s identity policy, and the customer-managed KMS key policy. Once that’s in place, the Python script handles the rest.
For more cross-account patterns, check out Setting Up Cross-Account S3 Upload with Lambda or Setting Up Cross-Account SNS to SQS Subscription in AWS.


