A simple tool to add, update and delete Mailtrap DNS verification records in Cloudflare DNS.
- Python 3.12*
- Cloudflare API token
- Mailtrap API token
uv
Python package and project manager (optional
)
To create a Cloudflare API token follow these steps:
- Go to https://dash.cloudflare.com/profile/api-tokens
- Click Create Token
- Click Create Custom Token at the bottom of the page
- Give your API token a descriptive name
mailtrap-verification-dns
- Select the following permissions:
- Zone - Zone - Read
- Zone - DNS - Edit
- Zone Resources
- specific zone - select the zone you want to add the DNS record to
- Click Continue to Summary
- Click Create Token
- Copy the generated token
- Save the token in a secure place. You won't be able to see it again.
To create a Mailtrap API token follow these steps:
- Go to https://mailtrap.io/api-tokens
- Copy the API token from the domain you want verification for.
Clone the repository and install the dependencies.
git clone git@github.com:difegam/mailtrap-cloudflare-dns.git
cd mailtrap-cloudflare-dns
uv
makes it easy to run the application. Install uv
and run the following command. Can it be any simpler?
uv run app --help
The previous command will create a virtual environment, install Python version required for the project (Python 3.12) and the dependencies, and show the help message of the application.
Create a .env
file in the root of the project with the following variables:
CLOUDFLARE_API_TOKEN=your-cloudflare-api-token
MAILTRAP_API_TOKEN=your-mailtrap-api-token
DOMAIN_NAME=example.com
If you don't want uv you can install the dependencies manually.
You must have Python 3.12 installed in your system.
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
Activate the virtual environment and run the application.
source venv/bin/activate
python src/mailtrap_cloudflare_dns/main.py --help
Using the tool is simple.
uv run app --load-env --action {create, overwrite, delete}
use the --load-env
flag to load the environment variables from the .env
file. You can also use the --cloudflare-api-token
, --mailtrap-api-token
, and --domain-name
flags to pass the values directly.
By default, the tool add a comment to all dns records to easily identify them on the Cloudflare dashboard. If you want to remove the comment, use the --comment ""
to pass an empty string.
- Add tests
- Create a Docker image
- Better error handling
- Add more DNS providers