- Newest
- Most votes
- Most comments
Hello,
SNS always uses no-reply@sns.amazonaws.com to send emails, but you can change its display name by setting the topic name.
For example:
You create a topic called Billing. When a user subscribes, the sender of the emails received from this topic will be displayed as Billing<no-reply@sns.amazonaws.com>
answered 2 years ago
Hello,
Customizing the "From" name for SNS emails isn't directly possible. However, you have options:
Use SES with SNS: Combine them, with a Lambda function using SES to send the email with your desired "From" name. (More complex setup).
Modify Email Content: Edit the email content within SNS to include a custom sender name in the body. (Less control).
Modify Email Content Within SNS:
While you can't customize the "From" name, you can modify the email content within SNS to include a custom sender name in the body of the email. This might not be ideal for all situations, but it provides some level of control over how the sender is identified.
Here's Python code for sending a custom SNS message:
import boto3
def lambda_handler(event, context):
message = "My Custom Message"
client = boto3.client('sns')
response = client.publish(
TargetArn="YOUR_ARN",
Message=message,
MessageStructure='text',
Subject='My Subject',
)
Check out the AWS SES documentation for details: https://docs.aws.amazon.com/ses/
Hi ajimimol,
Please go through the below steps i hope it will helps to resolve your issue.
1. Set Up Amazon SES
Verify Email Address/Domain:
* Go to SES Console and verify the email address or domain you want to use as the sender.
2. Create an SNS Topic
Create a Topic: * Go to SNS Console and create a new topic.
3. Create an AWS Lambda Function
* Go to Lambda Console and create a new function with the necessary permissions to invoke SES.
4. Configure the Lambda Function
- Write the Lambda Code:
import json
import boto3
def lambda_handler(event, context):
ses_client = boto3.client('ses')
sns_message = event['Records'][0]['Sns']
subject = sns_message['Subject']
message = sns_message['Message']
response = ses_client.send_email(
Source='customname@example.com',
Destination={'ToAddresses': ['recipient@example.com']},
Message={
'Subject': {'Data': subject, 'Charset': 'UTF-8'},
'Body': {'Text': {'Data': message, 'Charset': 'UTF-8'}}
}
)
return {'statusCode': 200, 'body': json.dumps('Email sent!')}
5. Subscribe Lambda to SNS Topic
Add Lambda as Subscriber:
- Go to SNS Console and subscribe the Lambda function to the SNS topic.
6. Publish Messages
* Send a Message:
* Publish messages to the SNS topic, which triggers the Lambda function to send emails via SES with the custom "From" name.
Modifying Email Content Within SNS
Alternatively, you can include a custom sender name in the email body:
import boto3
def send_sns_message():
sns_client = boto3.client('sns')
message = "From: Custom Sender\n\nMy Custom Message"
response = sns_client.publish(
TopicArn='YOUR_SNS_TOPIC_ARN',
Message=message,
Subject='My Subject',
)
print(response)
send_sns_message()
Please Go through with below documentation link once:
