0

I am trying to have an event-driven mail notification sent to all the people how have subscribed to the mail notification.

here is my code.

import json
import boto3
import uuid


def lambda_handler(event, context):
    item = json.loads(event['body'])
    amount = item['bid_amount']
    broker = item['posted_by_company']
    email = ["sumanth@xxxxxxx", "[email protected]"]
    email = ','.join(email)
    print (type(email))
    ses = boto3.client("ses")
    try:
        
        response = ses.send_email(
            Source = "xxxxxx@xxxxxx",
            Destination={
                'ToAddresses': [
                    email
                   
                ],
                'CcAddresses': [
                
                ]
            },
            Message={
                'Subject': {
                    'Data': "Your Bid has been Accepted" 
                },
                'Body': {
                    'Text': {
                        'Data': "Your Bid of amount $"+ amount +" has been accepted by " + broker + "\n"+
                        "Here are the Load details:\n" + 
                        "Load ID: \n" +
                        "Posted by: \n" 
                        
                    }
                }
            }
        )
        
        return {
            'statusCode': 200,
            'headers': {"Access-Control-Allow-Origin": "*"},
            'body': json.dumps('e-mail sent ')
        }
    except Exception as e:
        print(e)
        return {
            
            'statusCode': 500,
            'headers': {"Access-Control-Allow-Origin": "*"},
            'body': json.dumps('Error occured while sending an Bid e-mail')
        }

It seems to address takes an only string object. How do I pass all the e-mail received by an event in toAddress.?

1 Answer 1

1

If your email actually has the following form as you wrote:

email = ["sumanth@xxxxxxx", "[email protected]"]

then you can just pass it directly:

            Destination={
                'ToAddresses': email,

No need for email = ','.join(email).

Sign up to request clarification or add additional context in comments.

2 Comments

didn't think of it. so silly of me. Thank you so much as always :)
@sumanthshetty No problem. Glad it worked out:-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.