0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

curlスクリプト

Last updated at Posted at 2023-03-12
import boto3
import json
import logging

logger = logging.getLogger()
logger.setLevel(logging.ERROR)

ses = boto3.client('ses')

def lambda_handler(event, context):
    try:
        # リクエストボディからdeviceidを取得
        request_body = event['body']
        device_id = json.loads(request_body)['deviceid']

        # SESでメールを送信
        # Source/送信元メール
        # recipient_email/送信元メール
        recipient_email = 'test@test.mail.com'
        response = ses.send_email(
            Source='your-email-address@example.com',
            Destination={
                'ToAddresses': [recipient_email]
            },
            Message={
                'Subject': {
                    'Data': 'Test email'
                },
                'Body': {
                    'Text': {
                        'Data': f'This is a test email sent from AWS Lambda. Device ID: {device_id}'
                    }
                }
            }
        )

        return {
            'statusCode': 200,
            'body': json.dumps('Email sent successfully')
        }
    except Exception as e:
        logger.error('Failed to send email: ' + str(e))
        raise

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?