import smtplib
import boto3
from email.mime.text import MIMEText

# Retrieve SMTP credentials from AWS Secrets Manager
session = boto3.session.Session()
client = session.client(service_name='secretsmanager', region_name='your-aws-region')
get_secret_value_response = client.get_secret_value(SecretId='your-secret-name')
secret_value = get_secret_value_response['SecretString']

# Parse the secret value (assuming it's in a key=value format)
credentials = dict(line.split('=') for line in secret_value.splitlines())


# Extract SMTP credentials
smtp_host = 'vpce-xxxxx.email-smtp.aws-region.vpce.amazonaws.com'
smtp_username = credentials['smtp_username']
smtp_password = credentials['smtp_password']


# Email configuration
sender = "sender@example.com"
recipient = "recipient@example.com"
subject = "Test email from Amazon SES"
body = "This is a test email sent via Amazon SES using SMTP credentials stored in AWS Secrets Manager."


# Create the email message
msg = MIMEText(body)
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = recipient

# Connect to the SMTP server and send the email

with smtplib.SMTP(smtp_host) as smtp:
    smtp.starttls()
    smtp.login(smtp_username, smtp_password)
    smtp.send_message(msg)

print("Email sent successfully!")