title | author | date | output | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Sending automatic emails with attachment using Python, AWS-Lambda and S3 |
Danilo Arruda |
May, 2023 |
|
This script is designed to automatically send an email if specific criteria are met. In the case of the example, the script searches for emails from Paypal notifying that a customer bought a virtual product and then it sends email to the customer with the product attached.
In order to implement and run the script, the user must enable Gmail API and properly set up the AWS services: S3, Lambda, and Cloud Watch. In general, setting up the services are straight forward. The workflow is as follows:
-
Enable Gmail API;
-
Make an AWS account;
-
Create a S3 bucket with the files to be sent as attachment and the Python script
- Authorize Lambda to access the bucket (setting up IAM role - HERE)
-
Make a Lambda function by importing the Python script directly from S3 (click upload from)
-
Schedule the script to run at the desired frequency using CloudWatch
In addition, make sure to properly edit the script including the info about your API and specific bucket.