An AWS Lambda-based email bot that automatically creates and sends calendar invites when it receives emails containing event information (date, time, and location).
This bot monitors incoming emails sent to a specific email address and uses OpenAI's API to intelligently parse event details from email content. When event information is detected, it automatically generates and sends calendar invites to the original sender.
- Email Monitoring: Monitors incoming emails via AWS SES
- AI-Powered Parsing: Uses OpenAI API to extract event details from email content
- Automatic Calendar Invites: Generates and sends calendar invites via email
- Whitelist Security: Only processes emails from whitelisted addresses
- AWS Lambda Integration: Serverless deployment for cost-effectiveness
- Configurable: Easy configuration via environment variables
- AWS Account with access to:
- AWS Lambda
- Amazon SES (Simple Email Service)
- IAM (for permissions)
- OpenAI API key
- Domain with email capabilities (for receiving emails)
- Verify your domain in AWS SES
- Create an email receiving rule set
- Add a rule to forward emails to your Lambda function
- Create a new Lambda function
- Upload the deployment package
- Configure environment variables
- Set up SES trigger
Your Lambda function requires specific IAM permissions to work correctly. Create or update your Lambda execution role with the following permissions:
Required IAM Policy (JSON format):
Step-by-step IAM Setup:
-
Create IAM Role for Lambda:
- Go to AWS IAM Console → Roles → Create Role
- Select "Lambda" as the trusted entity
- Create a custom policy with the JSON above
- Name the role (e.g., calendar-bot-lambda-role)
-
Common Permission Issues and Solutions:
AccessDeniedException for ses:SendEmail:
- Ensure your FROM_EMAIL is verified in AWS SES
- Add ses:SendEmail and ses:SendRawEmail permissions
S3 GetObject errors:
- Replace your-s3-bucket-name with your actual S3 bucket name
- Ensure the Lambda role can read from the S3 bucket where SES stores emails
-
Attach Role to Lambda:
- In your Lambda function configuration
- Go to Configuration → Permissions
- Edit the execution role and select your created role
-
Verify SES Setup:
- Verify your sending email address in AWS SES Console
- If in SES sandbox, also verify recipient email addresses
- Check SES sending limits and quotas
| OPENAI_API_KEY | Your OpenAI API key | Yes |
| OPENAI_MODEL | OpenAI model to use (default: gpt-3.5-turbo) | No |
| FROM_EMAIL | Email address the bot sends from | Yes |
| WHITELISTED_EMAILS | Comma-separated list of allowed sender emails | Yes |
| ALLOW_PLUS_SIGN | Enables support for plus sign suffixes on email addresses. | No |
| SUBJECT_PREFIX | Invite emails subject will contain this prefix | No |
| DEFAULT_TIMEZONE | Timezone for event times (default: Europe/London) | No |
| REQUIRE_EMAIL_VERIFICATION | Require both SPF and DKIM verification to pass before processing emails (default: false) | No |
| LOG_LEVEL | Logging level: DEBUG, INFO, ERROR (default: INFO) | No |
| EMAIL_BUCKET | AWS region for SES operations | Yes |
| EMAIL_KEY_PREFIX | S3 key name prefix where SES stores email. Include the trailing slash. | No |
The bot only processes emails from addresses in the whitelist. Add email addresses to the WHITELISTED_EMAILS environment variable, separated by commas:
For enhanced security, you can enable email verification to ensure emails haven't been spoofed:
When enabled:
- The bot checks the Authentication-Results header from AWS SES
- Both SPF and DKIM verification must pass (spf=pass and dkim=pass)
- Emails with failed SPF or DKIM verification are rejected
- Emails without both SPF and DKIM information are rejected
When disabled (default):
- Email verification is skipped
- All whitelisted emails are processed regardless of SPF/DKIM status
Note: Email verification adds an extra layer of security but may reject legitimate emails from domains with misconfigured SPF or DKIM records. Test thoroughly before enabling in production.
- Email Reception: The bot receives emails via AWS SES
- Whitelist Check: Verifies the sender is in the whitelist
- Email Verification: Checks SPF and DKIM authenticity (if enabled)
- Content Analysis: Uses OpenAI to extract event information
- Calendar Generation: Creates calendar invite with extracted details
- Response: Sends calendar invite back to the original sender
The bot can parse event information from various email formats. It looks for:
- Date and time information
- Location details
- Event descriptions
The main handler function processes incoming SES events:
The bot uses OpenAI's API to intelligently parse email content and extract:
- Event date and time
- Location
- Event description
-
Emails not being processed
- Check SES configuration
- Verify Lambda trigger is set up correctly
- Check CloudWatch logs
-
Calendar invites not being sent
- Verify sender email is verified in SES
- Check IAM permissions
- Review OpenAI API key validity
-
OpenAI API errors
- Check API key validity
- Verify account has sufficient credits
- Check rate limits
This project is licensed under the MIT License - see the LICENSE-MIT file for details.
- Inspired by aws-lambda-ses-forwarder
- Uses OpenAI API for intelligent email parsing
- Built with AWS Lambda and SES
.png)


