Aws ses mail from
AWS SES (Simple Email Service) allows you to send and receive emails programmatically. Here's a step-by-step guide on how to send an email from AWS SES:
Prerequisites:
- You have an AWS account and have created an SES identity (email address or domain).
- You have verified your email address or domain with SES.
- You have installed the AWS SDK or CLI on your machine.
Step 1: Create an SES client
You can create an SES client using the AWS SDK or CLI. Here's an example using the AWS SDK for Python (Boto3):
import boto3
ses = boto3.client('ses', region_name='your-region')
Replace your-region
with the region where your SES identity is located.
Step 2: Set up the email
Create a dictionary to hold the email details:
email = {
'Destination': {
'ToAddresses': ['[email protected]'],
'CcAddresses': [],
'BccAddresses': []
},
'Message': {
'Body': {
'Text': {
'Data': 'Hello, this is a test email from AWS SES!'
}
},
'Subject': {
'Data': 'Test email from AWS SES'
}
},
'Source': '[email protected]'
}
Replace [email protected]
with the email address of the recipient, and [email protected]
with the email address you verified with SES.
Step 3: Send the email
Use the SES client to send the email:
response = ses.send_email(**email)
The send_email
method returns a response object that contains the status of the email send operation.
Example code
Here's the complete example code in Python:
import boto3
ses = boto3.client('ses', region_name='your-region')
email = {
'Destination': {
'ToAddresses': ['[email protected]'],
'CcAddresses': [],
'BccAddresses': []
},
'Message': {
'Body': {
'Text': {
'Data': 'Hello, this is a test email from AWS SES!'
}
},
'Subject': {
'Data': 'Test email from AWS SES'
}
},
'Source': '[email protected]'
}
response = ses.send_email(**email)
print(response)
Make sure to replace the placeholders with your actual email address and recipient's email address.
That's it! You should now be able to send an email from AWS SES using the AWS SDK or CLI.