### Run OpenTrashmail Web UI Source: https://github.com/hascheksolutions/opentrashmail/blob/master/docs/Dev.md Starts a local PHP development server for the OpenTrashmail web UI. Access it at http://localhost:8080. No database is required. ```bash php -S localhost:8080 index.php ``` -------------------------------- ### Webhook Payload Template Example Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md An example JSON payload template for configuring webhooks. It demonstrates how to use placeholders to include email details in the sent data. ```json { "email": "{{to}}", "from": "{{from}}", "subject": "{{subject}}", "body": "{{body}}", "attachments": {{attachments}} } ``` -------------------------------- ### Run OpenTrashmail with Docker (Simple) Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Deploy OpenTrashmail using Docker with basic port forwarding and a specified URL. No data persistence is configured in this simple setup. ```bash docker run -it -p 25:25 -p 80:80 -e URL="https://localhost:80" hascheksolutions/opentrashmail:1 ``` -------------------------------- ### Run OpenTrashmail with Docker (Complete Configuration) Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md A comprehensive Docker deployment example including background execution, persistence, custom domain, date format, discarding unknown emails, mail cleanup, and auto-restart. ```bash docker run -d --restart=unless-stopped --name opentrashmail -e "DOMAINS=mydomain.eu" -e "DATEFORMAT='D.M.YYYY HH:mm'" -e "DISCARD_UNKNOWN=false" -e "DELETE_OLDER_THAN_DAYS=90" -p 80:80 -p 25:25 -v /path/on/host/where/to/save/data:/var/www/opentrashmail/data hascheksolutions/opentrashmail:1 ``` -------------------------------- ### Local Development Setup for Open Trashmail Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Instructions for local development, including serving the web UI with PHP's built-in server and running the mail server via Docker with specific volume and configuration mounts. ```bash # Serve the web UI locally on port 8080 cd web/ php -S localhost:8080 index.php ``` ```bash # Build and run only the mail server via Docker (binds SMTP to port 2525) docker build -f docker/Dockerfile -t opentrashmail . docker run --rm -it --name trashmail \ -p 2525:25 \ -v $(pwd)/data:/var/www/opentrashmail/data \ -v $(pwd)/logs:/var/www/opentrashmail/logs \ -v $(pwd)/config.ini:/var/www/opentrashmail/config.ini:ro \ opentrashmail ``` -------------------------------- ### Send Test Email via Swaks with STARTTLS Source: https://github.com/hascheksolutions/opentrashmail/blob/master/docs/Dev.md Tests sending an email using swaks with STARTTLS to the local mail server. This method starts in plaintext and upgrades to TLS. Requires TLS_CERTIFICATE and TLS_PRIVATE_KEY to be set in the configuration. ```bash echo 'Testing' | swaks --to test@example.com --from "something@example.com" --server localhost --port 465 -tlsc ``` -------------------------------- ### Configure MX Records for Domain Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Set up MX records in your DNS panel to direct emails to your OpenTrashmail server. This example shows basic and wildcard domain configurations. ```zonefile mail.example.com. IN A 93.184.216.34 example.com. 14400 IN MX 10 mail.example.com. ``` ```zonefile mail.example.com. IN A 93.184.216.34 *.example.com. 14400 IN MX 10 mail.example.com. ``` -------------------------------- ### Get Webhook Configuration Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Retrieves the current webhook settings for a specified email address. Returns configuration details if enabled, or a simple 'enabled: false' object if not configured. ```bash curl http://localhost:8080/api/webhook/get/test@example.com ``` -------------------------------- ### Webhook Configuration - Get Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Retrieves the current webhook configuration for a specified email address. ```APIDOC ## Get Webhook Configuration ### Description Retrieves the webhook configuration for a specific email address. ### Method GET ### Endpoint /api/webhook/get/[email-address] ### Parameters #### Path Parameters - **email-address** (string) - Required - The email address for which to retrieve webhook configuration. ``` -------------------------------- ### Docker Quick Start for Open Trashmail Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Run Open Trashmail using Docker. The first command is for a simple run without persistence, while the subsequent commands demonstrate persistent data volumes and production-ready configurations with various options. ```bash # Simple run (no persistence) docker run -it -p 25:25 -p 80:80 \ -e URL="http://localhost:80" \ hascheksolutions/opentrashmail:1 ``` ```bash # With persistent data volume docker run -p 80:80 -p 25:25 \ -e URL="http://trashmail.example.com" \ -v /srv/trashmail/data:/var/www/opentrashmail/data \ hascheksolutions/opentrashmail:1 ``` ```bash # Production: daemon mode, custom domain, auto-cleanup, auto-restart docker run -d --restart=unless-stopped --name opentrashmail \ -e URL="https://trashmail.example.com" \ -e DOMAINS="example.com,*.example.com" \ -e DISCARD_UNKNOWN=true \ -e DELETE_OLDER_THAN_DAYS=90 \ -e PASSWORD="s3cr3t" \ -e SHOW_ACCOUNT_LIST=true \ -e ADMIN_ENABLED=true \ -e ADMIN_PASSWORD="adminpass" \ -e DATEFORMAT="D.M.YYYY HH:mm" \ -p 80:80 -p 25:25 \ -v /srv/trashmail/data:/var/www/opentrashmail/data \ hascheksolutions/opentrashmail:1 ``` -------------------------------- ### Open Trashmail Configuration (config.ini) Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Example configuration file for Open Trashmail, detailing settings for domains, URL, security, mail server ports, TLS, attachment size, date formatting, cleanup, webhooks, and admin access. ```ini [GENERAL] ; Domains to accept mail for (comma-separated, wildcard supported) DOMAINS=example.com,*.example.com ; Public URL for the web interface (no trailing slash) URL=https://trashmail.example.com ; Optional: protect site and API with a password ; Send via HTTP header "PWD", GET/POST parameter "password" PASSWORD=mystrongpassword ; Optional: restrict access by IP/CIDR range ALLOWED_IPS=192.168.0.0/16,2a02:ab:cd:ef::/60 [MAILSERVER] MAILPORT=25 ; TLS-on-connect port (needs certificate settings below) MAILPORT_TLS=465 TLS_CERTIFICATE=/certs/fullchain.pem TLS_PRIVATE_KEY=/certs/privkey.pem ; Reject emails not addressed to DOMAINS DISCARD_UNKNOWN=true ; Max attachment size in bytes (0 = unlimited) ATTACHMENTS_MAX_SIZE=2000000 [DATETIME] DATEFORMAT="D.M.YYYY HH:mm" [CLEANUP] ; Delete emails older than N days (false = keep forever) DELETE_OLDER_THAN_DAYS=90 [WEBHOOK] ; Global webhook: POSTs full email JSON to this URL on every received email WEBHOOK_URL=https://hooks.example.com/mail [ADMIN] ADMIN_ENABLED=true ADMIN_PASSWORD=adminpass SHOW_ACCOUNT_LIST=true ; Entering this address shows ALL emails from ALL accounts (catch-all) ADMIN=catchall@example.com SHOW_LOGS=true ``` -------------------------------- ### Get Webhook Configuration Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Retrieves the current webhook configuration for a specified email address, including its status, URL, payload template, and retry settings. ```APIDOC ## GET /api/webhook/get/[email] ### Description Returns the current webhook configuration for an email address. ### Method GET ### Endpoint `/api/webhook/get/[email]` ### Parameters #### Path Parameters - **email** (string) - Required - The email address for which to retrieve the webhook configuration. ### Request Example ```bash curl http://localhost:8080/api/webhook/get/test@example.com ``` ### Response #### Success Response (200) - **enabled** (boolean) - Indicates if webhooks are enabled for the address. - **webhook_url** (string) - The URL where webhook notifications are sent. - **payload_template** (string) - A template for the webhook payload. - **retry_config** (object) - Configuration for retrying webhook delivery. - **max_attempts** (integer) - Maximum number of retry attempts. - **backoff_multiplier** (integer) - Multiplier for backoff delay between retries. - **secret_key** (string) - A secret key used for webhook signature verification. ### Response Example (configured) ```json { "enabled": true, "webhook_url": "https://myapi.example.com/hook", "payload_template": "{\"email\":\"{{to}}\",\"subject\":\"{{subject}}\"}", "retry_config": { "max_attempts": 5, "backoff_multiplier": 2 }, "secret_key": "mysecret" } ``` ### Response Example (not configured) ```json { "enabled": false } ``` ``` -------------------------------- ### Docker Compose for Open Trashmail Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Defines a Docker Compose setup for Open Trashmail, including service configuration, ports, environment variables for customization, and volume mounts for data persistence. ```yaml # docker-compose.yml version: "3" services: opentrashmail: image: hascheksolutions/opentrashmail:1 restart: unless-stopped ports: - "25:25" - "80:80" environment: URL: "https://trashmail.example.com" DOMAINS: "example.com,*.example.com" DISCARD_UNKNOWN: "true" DELETE_OLDER_THAN_DAYS: "90" PASSWORD: "s3cr3t" WEBHOOK_URL: "https://hooks.example.com/mail" volumes: - ./data:/var/www/opentrashmail/data - ./logs:/var/www/opentrashmail/logs ``` -------------------------------- ### Get Raw Email Source Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Retrieves the raw SMTP email source, including headers and body, as plain text. This can be large for emails with attachments. ```bash curl http://localhost:8080/api/raw/test@example.com/1714000000000 ``` -------------------------------- ### Fetch Emails via JSON API Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Example using curl to fetch a list of received email summaries for a specific email address via the Open Trashmail JSON API. This basic fetch does not require authentication. ```bash # Basic fetch (no auth) curl http://localhost:8080/json/test@example.com ``` -------------------------------- ### Get HTML Body Only Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Extracts and returns only the HTML body of an email, with inline images resolved. This is useful for displaying email content in a web view. ```bash curl http://localhost:8080/api/raw-html/test@example.com/1714000000000 ``` -------------------------------- ### Webhook Management API Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md These API endpoints allow you to manage webhook configurations for specific email addresses. You can get, save, and delete webhook configurations. ```APIDOC ## Webhook Management API ### Get Webhook Configuration - **Endpoint**: `/api/webhook/get/[email]` - **Method**: GET - **Description**: Retrieves the webhook configuration for a given email address. ### Save Webhook Configuration - **Endpoint**: `/api/webhook/save/[email]` - **Method**: POST - **Description**: Saves or updates the webhook configuration for a given email address. - **Parameters**: - `enabled` (boolean) - Required - Whether the webhook is enabled. - `webhook_url` (string) - Required - The URL to send webhook notifications to. - `payload_template` (string) - Optional - A template for the JSON payload. - `max_attempts` (integer) - Optional - Maximum number of retry attempts. - `secret_key` (string) - Optional - A secret key for signing requests. ### Delete Webhook Configuration - **Endpoint**: `/api/webhook/delete/[email]` - **Method**: DELETE - **Description**: Deletes the webhook configuration for a given email address. ### Save Webhook Example ```bash curl -X POST http://localhost:8080/api/webhook/save/test@example.com \ -d "enabled=true" \ -d "webhook_url=https://myapi.com/webhook" \ -d 'payload_template={"email":"{{to}}","subject":"{{subject}}"}' \ -d "max_attempts=5" \ -d "secret_key=your-secret-key" ``` ``` -------------------------------- ### Get Full Email by ID Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Retrieve the complete parsed email, including raw source, HTML body, and attachment details, by specifying the email address and a unique message ID. ```bash curl http://localhost:8080/json/test@example.com/1714000000000 ``` -------------------------------- ### SMTP Email with Quoted-Printable Source: https://github.com/hascheksolutions/opentrashmail/blob/master/tools/testmail-quotedprintable.txt This example shows a full SMTP transaction including EHLO, MAIL FROM, RCPT TO, DATA, and QUIT commands. It demonstrates MIME encapsulation with multipart/alternative content, using quoted-printable for the plain text part and base64 for the HTML part. ```smtp EHLO example.com MAIL FROM: RCPT TO: DATA From: me To: you Subject: MIME encapsulation demo Mime-Version: 1.0 Content-type: multipart/alternative; boundary="covfefe" --covfefe Content-type: text/plain; charset="utf-8" Content-transfer-encoding: quoted-printable You had me at "H= ello." --covfefe Content-type: text/html; charset="utf-8" Content-transfer-encoding: base64 PGh0bWw+PGhlYWQ+PHRpdGxlPkhlbGxvLCBpdCBtZSB5b3UncmUgbG9va2luZyBmb3I/PC90aXRsZT48L2hlYWQ+PGJvZHk+PHA+VGhlIGNvdiBpbiB0aGUgZmUgZmU8L3A+PC9ib2R5Pj /aHRtbD4K --covfefe-- . QUIT ``` -------------------------------- ### GET /json/[email] — List all emails for an address Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Retrieves a list of all received emails for a specific email address. The response includes summaries containing sender, subject, body, and attachment URLs. ```APIDOC ## GET /json/[email] — List all emails for an address ### Description Returns an array of received email summaries with sender, subject, body, and attachment URLs. ### Method GET ### Endpoint /json/[email] ### Parameters #### Path Parameters - **email** (string) - Required - The email address for which to list emails. ### Request Example ```bash curl http://localhost:8080/json/test@example.com ``` ### Response #### Success Response (200) - **sender** (string) - The sender of the email. - **subject** (string) - The subject of the email. - **body** (string) - The body content of the email. - **attachments** (array) - A list of attachment URLs. #### Response Example ```json [ { "sender": "sender@example.com", "subject": "Test Email", "body": "This is the email body.", "attachments": ["http://localhost:8080/attachments/test@example.com/12345/file.txt"] } ] ``` ``` -------------------------------- ### Get Emails by Address Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Retrieves a list of received emails for a specific email address. If the 'ADMIN' email is used, it returns all emails from all accounts. Includes links to attachments and the parsed text-based body. ```APIDOC ## GET /json/[email-address] ### Description Returns an array of received emails with links to the attachments and the parsed text based body of the email. If `ADMIN` email is entered, will return all emails of all accounts. ### Method GET ### Endpoint /json/[email-address] ### Parameters #### Path Parameters - **email-address** (string) - Required - The email address to retrieve emails for, or the ADMIN email to get all emails. ### Response #### Success Response (200) - **Array of email objects**: Each object contains details like sender, subject, date, body, and attachment links. ``` -------------------------------- ### Get Specific Email by ID Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Fetches the complete data for a specific email, identified by its ID. This includes the raw and HTML body, potentially containing attachments in base64 encoding. ```APIDOC ## GET /json/[email-address]/[id] ### Description To see all the data of a received email, take the ID from the previous call and poll this to get the raw and HTML body of the email. Can be huge since the body can contain all attachments in base64. ### Method GET ### Endpoint /json/[email-address]/[id] ### Parameters #### Path Parameters - **email-address** (string) - Required - The email address associated with the email. - **id** (string) - Required - The unique identifier of the email. ### Response #### Success Response (200) - **Email object**: Contains raw body, HTML body, and attachments in base64. ``` -------------------------------- ### Get Full Email by ID Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Retrieves the complete parsed email content, including raw source, HTML body, and detailed attachment information, using the email address and message ID. ```APIDOC ## GET /json/[email]/[id] ### Description Returns the complete parsed email including raw source, HTML body, and attachment details. ### Method GET ### Endpoint `/json/[email]/[id]` ### Parameters #### Path Parameters - **email** (string) - Required - The email address. - **id** (string) - Required - The unique identifier of the email. ### Request Example ```bash curl http://localhost:8080/json/test@example.com/1714000000000 ``` ### Response #### Success Response (200) - **sender_ip** (string) - The IP address from which the email was sent. - **from** (string) - The sender's email address. - **rcpts** (array) - A list of recipient email addresses. - **raw** (string) - The raw MIME content of the email. - **parsed** (object) - Parsed email content. - **subject** (string) - The subject of the email. - **body** (string) - The plain text body of the email. - **htmlbody** (string) - The HTML body of the email. - **from** (string) - The sender's email address. - **attachments** (array) - A list of attachment filenames. - **attachments_details** (array) - Detailed information about each attachment. - **filename** (string) - The name of the attachment file. - **cid** (string) - The content ID of the attachment. - **id** (string) - The unique identifier for the attachment. - **download_url** (string) - The URL to download the attachment. - **size** (integer) - The size of the attachment in bytes. ### Response Example ```json { "sender_ip": "192.168.1.100", "from": "sender@domain.com", "rcpts": ["test@example.com"], "raw": "From: sender@domain.com\r\nTo: test@example.com\r\n...", "parsed": { "subject": "Hello World", "body": "Plain text body", "htmlbody": "

HTML body with inline images resolved

", "from": "sender@domain.com", "attachments": ["abc123def456report.pdf"], "attachments_details": [ { "filename": "report.pdf", "cid": "unique-content-id", "id": "abc123def456report.pdf", "download_url": "http://localhost:8080/api/attachment/test@example.com/abc123def456report.pdf", "size": 204800 } ] } } ``` ``` -------------------------------- ### Poll for Verification Emails and Extract OTP Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt This Python script polls for emails containing a specific subject, extracts the full email details, and then uses regex to find a 6-digit OTP from the email body. It includes setup for the Open Trashmail server, email address, password, and cleanup. ```python import requests, re, time BASE = "http://localhost:8080" ADDRESS = "signup-test@example.com" PWD = "s3cr3t" HEADERS = {"PWD": PWD} def wait_for_email(address, subject_contains, timeout=60): """Poll until an email matching subject_contains arrives.""" deadline = time.time() + timeout seen_ids = set() while time.time() < deadline: r = requests.get(f"{BASE}/json/{address}", headers=HEADERS) r.raise_for_status() emails = r.json() for email_id, meta in emails.items(): if email_id in seen_ids: continue if subject_contains.lower() in meta["subject"].lower(): # Fetch full email for body detail = requests.get( f"{BASE}/json/{address}/{email_id}", headers=HEADERS ).json() return detail seen_ids.add(email_id) time.sleep(3) raise TimeoutError(f"No matching email arrived within {timeout}s") # Example: extract a 6-digit OTP from an email body email = wait_for_email(ADDRESS, "Your verification code") body = email["parsed"]["body"] code = re.search(r'\b(\d{6})\b', body).group(1) print("OTP:", code) # Clean up requests.get(f"{BASE}/api/deleteaccount/{ADDRESS}", headers=HEADERS) ``` -------------------------------- ### Send Test Email via Swaks (STARTTLS) Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Sends a test email using swaks with STARTTLS on the standard port 25. Specify recipient, sender, server, and port. ```bash echo 'Test' | swaks \ --to test@example.com \ --from sender@example.com \ --server localhost \ --port 25 \ --tls ``` -------------------------------- ### Fetch Email with Password Authentication (Header) Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Use this endpoint to retrieve email content by providing the password in the 'PWD' header. Ensure the email address and password are correct. ```bash curl -H "PWD: s3cr3t" http://localhost:8080/json/test@example.com ``` -------------------------------- ### Fetch Emails with Password Authentication Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Demonstrates how to fetch emails for a specific address using password authentication, either via a header or a query parameter. ```APIDOC ## GET /json/[email] ### Description Fetches a list of emails for a given email address, supporting password authentication. ### Method GET ### Endpoint `/json/[email]` ### Parameters #### Query Parameters - **password** (string) - Optional - The password for authentication. #### Headers - **PWD** (string) - Optional - The password for authentication. ### Request Example ```bash # With password authentication via header curl -H "PWD: s3cr3t" http://localhost:8080/json/test@example.com # With password as query parameter curl "http://localhost:8080/json/test@example.com?password=s3cr3t" ``` ### Response #### Success Response (200) - **[timestamp]** (object) - An object where keys are timestamps and values are email details. - **email** (string) - The recipient email address. - **id** (string) - The unique identifier for the email. - **from** (string) - The sender's email address. - **subject** (string) - The subject of the email. - **body** (string) - The plain text body of the email. - **md5** (string) - The MD5 hash of the email content. - **maillen** (integer) - The size of the email in bytes. - **attachments** (array) - A list of URLs for email attachments. ### Response Example ```json { "1714000000000": { "email": "test@example.com", "id": "1714000000000", "from": "sender@domain.com", "subject": "Hello World", "body": "Plain text body content", "md5": "abc123...", "maillen": 1024, "attachments": [ "http://localhost:8080/api/attachment/test@example.com/abc123def456report.pdf" ] } } ``` ``` -------------------------------- ### Run OpenTrashmail with Docker (Persistent Data) Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Deploy OpenTrashmail using Docker, mapping a host directory to the container's data volume for persistent storage of emails and attachments. ```bash docker run -p 80:80 -p 25:25 -e URL="https://localhost:80" -v /path/on/host/where/to/save/data:/var/www/opentrashmail/data hascheksolutions/opentrashmail:1 ``` -------------------------------- ### Build and Run OpenTrashmail Mail Server with Docker Source: https://github.com/hascheksolutions/opentrashmail/blob/master/docs/Dev.md Builds the Docker image for the OpenTrashmail mail server and runs it as a container. This maps ports and local directories for data and logs, allowing received emails to be stored locally. ```bash docker build -f docker/Dockerfile -t opentrashmail . docker run --rm -it --name trashmail -p 2525:25 \ -v $( pwd )/data:/var/www/opentrashmail/data \ -v $( pwd )/logs:/var/www/opentrashmail/logs \ -v $( pwd )/config.ini:/var/www/opentrashmail/config.ini:ro opentrashmail ``` -------------------------------- ### Test Webhook Script Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Utilize the provided bash script for quick webhook testing. It supports sending emails and verifying signatures when a secret key is provided. ```bash # Simple test python3 tools/test_webhook.py test@example.com --send-email # With signature verification python3 tools/test_webhook.py test@example.com --secret "your-secret-key" --send-email ``` -------------------------------- ### Test Webhook Configuration Script Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Tests webhook configuration using the provided script. Can send a test email and optionally verify HMAC signature if a secret is provided. ```bash # Simple test (fires a test webhook for an address) python3 tools/test_webhook.py test@example.com --send-email # With HMAC signature verification python3 tools/test_webhook.py test@example.com \ --secret "mysecret" \ --send-email ``` -------------------------------- ### Fetch Email with Password Authentication (Query Parameter) Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Retrieve email content by including the password as a query parameter in the URL. This method is an alternative to using the 'PWD' header. ```bash curl "http://localhost:8080/json/test@example.com?password=s3cr3t" ``` -------------------------------- ### Send Test Email via Swaks (TLS-on-connect) Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Sends a test email using swaks with TLS-on-connect on port 465. Specify recipient, sender, server, and port. ```bash echo 'Test' | swaks \ --to test@example.com \ --from sender@example.com \ --server localhost \ --port 465 \ --tlsc ``` -------------------------------- ### SMTP Commands for Sending a Test Email Source: https://github.com/hascheksolutions/opentrashmail/blob/master/tools/testmail.txt This snippet shows the sequence of SMTP commands to initiate an email transaction, including specifying sender and recipient, and initiating the data transfer. It's useful for testing mail server configurations. ```smtp EHLO example.com MAIL FROM: RCPT TO: DATA Subject: Your Subject From: sender@example.com To: recipient@example.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="boundary-string" --boundary-string Content-Type: multipart/alternative; boundary="alternative-boundary" --alternative-boundary Content-Type: text/plain This is the plaintext part of the email. --alternative-boundary Content-Type: text/html


This is the HTML part of the email.

--alternative-boundary-- --boundary-string Content-Type: image/svg+xml Content-Id: Content-Disposition: attachment; filename="42.svg" 42 --boundary-string-- . QUIT ``` -------------------------------- ### Send Test Email via Netcat Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Simulates an SMTP dialogue using netcat to send a test email. Ensure the test mail file is correctly formatted. ```bash # Use the included test mail file to simulate SMTP dialogue cat tools/testmail.txt | while read L; do sleep "0.2"; echo "$L"; done \ | nc -C -v localhost 2525 ``` -------------------------------- ### List All Email Accounts Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Fetches a list of all email addresses that have received at least one email. This endpoint requires the 'SHOW_ACCOUNT_LIST' configuration to be enabled and password authentication. ```bash curl -H "PWD: adminpass" http://localhost:8080/json/listaccounts ``` -------------------------------- ### Send Test Email via Swaks with TLS Source: https://github.com/hascheksolutions/opentrashmail/blob/master/docs/Dev.md Tests sending an email using swaks with TLS encryption to the local mail server. Requires specific configuration options in config.ini for MAILPORT_TLS, TLS_CERTIFICATE, and TLS_PRIVATE_KEY. ```bash echo 'Testing' | swaks --to test@example.com --from "something@example.com" --server localhost --port 2525 -tlsc ``` -------------------------------- ### DNS MX Record Configuration Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Configures DNS MX records for a domain to point to the Open Trashmail server. Supports single domain and wildcard subdomains. ```zonefile ; Single domain mail.example.com. IN A 93.184.216.34 example.com. IN MX 10 mail.example.com. ; Wildcard (any subdomain, e.g. test@robot.example.com) mail.example.com. IN A 93.184.216.34 *.example.com. IN MX 10 mail.example.com. ``` -------------------------------- ### Send Test Email via Netcat Source: https://github.com/hascheksolutions/opentrashmail/blob/master/docs/Dev.md Sends emails from a test file to the local mail server using netcat. Ensure the mail server is running and accessible on localhost:2525. A short delay is introduced between lines. ```bash cat "tools/testmail.txt" | while read L; do sleep "0.2"; echo "$L"; done | "nc" -C -v "localhost" "2525" ``` -------------------------------- ### Generate Self-Signed TLS Certificate Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Use this command to generate a self-signed certificate and private key for testing TLS configurations. The certificate is valid for 365 days and is generated for the 'localhost' hostname. ```bash openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj '/CN=localhost' ``` -------------------------------- ### List All Accounts Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Returns an array of all email addresses that have received at least one email, provided that the `SHOW_ACCOUNT_LIST` configuration is set to true. ```APIDOC ## GET /json/listaccounts ### Description If `SHOW_ACCOUNT_LIST` is set to true in the config.ini, this endpoint will return an array of all email addresses which have received at least one email. ### Method GET ### Endpoint /json/listaccounts ### Response #### Success Response (200) - **Array of email addresses**: A list of email addresses that have received mail. ``` -------------------------------- ### Download Attachment Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Streams a specific email attachment, setting the correct MIME type and Content-Length headers. Use the '-o' flag to save the file locally. ```bash curl -o report.pdf \ http://localhost:8080/api/attachment/test@example.com/abc123def456report.pdf ``` -------------------------------- ### Generate Random Email Address Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Creates a new, random email address in the format 'adjective.noun@configured-domain.com' and returns an HTML fragment for its inbox. The inbox is initially empty. ```bash curl http://localhost:8080/api/random ``` -------------------------------- ### RSS Feed for Email Address Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Generates an RSS 2.0 feed for a given email address, compatible with standard RSS readers. This allows for easy subscription to new emails. ```bash curl http://localhost:8080/rss/test@example.com ``` -------------------------------- ### Save Webhook Configuration Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Saves a per-email webhook configuration. Supports SSRF blocking, JSON payload validation, and retries with exponential backoff. Ensure max attempts are between 1 and 10. ```bash curl -X POST http://localhost:8080/api/webhook/save/test@example.com \ -d "enabled=true" \ -d "webhook_url=https://myapi.example.com/hook" \ -d 'payload_template={"email":"{{to}}","from":"{{from}}","subject":"{{subject}}","body":"{{body}}","attachments":{{attachments}}}' \ -d "max_attempts=5" \ -d "backoff_multiplier=2" \ -d "secret_key=mysecret" ``` -------------------------------- ### Verify Webhook Signature in Python Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md This Python function demonstrates how to verify webhook signatures using HMAC-SHA256. It requires the request body and the 'X-Webhook-Signature' header. ```python import hmac import hashlib def verify_webhook(request): payload = request.body signature = request.headers.get('X-Webhook-Signature', '') expected = hmac.new( b'your-secret-key', payload, hashlib.sha256 ).hexdigest() if not hmac.compare_digest(expected, signature): return HttpResponse('Invalid signature', status=401) ``` -------------------------------- ### Download Attachment Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Streams a specific email attachment, setting the correct MIME type and content length headers for direct download. ```APIDOC ## GET /api/attachment/[email]/[attachment-id] ### Description Streams the attachment with the correct MIME type header. ### Method GET ### Endpoint `/api/attachment/[email]/[attachment-id]` ### Parameters #### Path Parameters - **email** (string) - Required - The email address. - **attachment-id** (string) - Required - The unique identifier of the attachment. ### Request Example ```bash curl -o report.pdf \ http://localhost:8080/api/attachment/test@example.com/abc123def456report.pdf ``` ### Response #### Success Response (200) - **(binary)** - The attachment file content with appropriate Content-Type and Content-Length headers. ### Response Example ``` Streams the file with Content-Type and Content-Length headers set ``` ``` -------------------------------- ### Save Webhook Configuration Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Saves a per-email webhook configuration. It validates the payload as JSON and includes retry mechanisms with exponential backoff. It also blocks SSRF attacks by disallowing localhost or private IP addresses. ```APIDOC ## POST /api/webhook/save/[email] — Save webhook configuration Saves a per-email webhook. Blocks SSRF (localhost/private IPs). Validates payload as JSON. Retries up to 10 times with exponential backoff. ### Method POST ### Endpoint /api/webhook/save/[email] ### Parameters #### Path Parameters - **email** (string) - Required - The email address for which to save the webhook configuration. #### Request Body - **enabled** (boolean) - Required - Whether the webhook is enabled. - **webhook_url** (string) - Required - The URL to send webhook notifications to. - **payload_template** (string) - Required - A JSON string template for the webhook payload. Supports placeholders like `{{to}}`, `{{from}}`, etc. - **max_attempts** (integer) - Optional - Maximum number of retry attempts for sending webhooks (1-10). - **backoff_multiplier** (integer) - Optional - Multiplier for exponential backoff during retries. - **secret_key** (string) - Optional - A secret key used for HMAC signature verification. ### Request Example ```bash curl -X POST http://localhost:8080/api/webhook/save/test@example.com \ -d "enabled=true" \ -d "webhook_url=https://myapi.example.com/hook" \ -d 'payload_template={"email":"{{to}}","from":"{{from}}","subject":"{{subject}}","body":"{{body}}","attachments":{{attachments}}}' \ -d "max_attempts=5" \ -d "backoff_multiplier=2" \ -d "secret_key=mysecret" ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. - **message** (string) - A message confirming the webhook configuration was saved. #### Response Example ```json { "success": true, "message": "Webhook configuration saved" } ``` #### Error Responses - **Invalid webhook URL** - **Webhook URL cannot point to private IP addresses** - **Invalid JSON in payload template** - **Max attempts must be between 1 and 10** ### Payload template placeholders: | Placeholder | Value | |---|---| | `{{to}}` | Recipient email address | | `{{from}}` | Sender email address | | `{{subject}}` | Email subject line | | `{{body}}` | Plain text body | | `{{htmlbody}}` | HTML body | | `{{sender_ip}}` | Sender's IP address | | `{{attachments}}` | JSON array of attachment objects (no quotes!) | ``` -------------------------------- ### RSS Feed Endpoint Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Renders an RSS XML feed for a specific email address, allowing RSS clients to display incoming emails. ```APIDOC ## RSS Feed ### Description Provides an RSS feed for a given email address. ### Method GET ### Endpoint /rss/[email-address] ### Parameters #### Path Parameters - **email-address** (string) - Required - The email address for which to generate the RSS feed. ``` -------------------------------- ### Generate Random Email Address Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Creates a new, random email address in the format `adjective.noun@configured-domain.com` and returns its associated (initially empty) inbox. ```APIDOC ## GET /api/random ### Description Generates a random `adjective.noun@configured-domain.com` address and returns its (empty) inbox. ### Method GET ### Endpoint `/api/random` ### Request Example ```bash curl http://localhost:8080/api/random ``` ### Response #### Success Response (200) - **(HTML fragment)** - An HTML fragment representing the email table for the newly generated address. ### Response Example ``` Returns the email-table HTML fragment for the newly generated address, e.g. for "happy.aardvark@example.com" ``` ``` -------------------------------- ### List All Email Accounts Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Retrieves a list of all email addresses that have received at least one email. This endpoint requires a specific configuration to be enabled. ```APIDOC ## GET /json/listaccounts ### Description Returns all email addresses that have received at least one email. Requires `SHOW_ACCOUNT_LIST=true`. ### Method GET ### Endpoint `/json/listaccounts` ### Parameters #### Headers - **PWD** (string) - Required - The password for authentication (e.g., `adminpass`). ### Request Example ```bash curl -H "PWD: adminpass" http://localhost:8080/json/listaccounts ``` ### Response #### Success Response (200) - **(array of strings)** - A list of email addresses. ### Response Example ```json ["alice@example.com", "test@example.com", "robot@sub.example.com"] ``` ``` -------------------------------- ### Raw Email Source Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Retrieves the complete raw SMTP source of an email, including headers and body. This can be very large for emails with attachments. ```APIDOC ## GET /api/raw/[email]/[id] ### Description Returns the raw SMTP email source as `text/plain`. Can be large for emails with attachments. ### Method GET ### Endpoint `/api/raw/[email]/[id]` ### Parameters #### Path Parameters - **email** (string) - Required - The email address. - **id** (string) - Required - The unique identifier of the email. ### Request Example ```bash curl http://localhost:8080/api/raw/test@example.com/1714000000000 ``` ### Response #### Success Response (200) - **(text/plain)** - The raw MIME email text (headers + body). ### Response Example ``` raw MIME email text (headers + body) ``` ``` -------------------------------- ### Webhook Signature Verification (Python) Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Verifies the HMAC-SHA256 signature of incoming webhook POST requests in Python using Flask. Ensure the secret key is correctly configured. ```python # Python verification import hmac, hashlib from flask import request, abort SECRET = b'mysecret' def verify_webhook(): payload = request.get_data() signature = request.headers.get('X-Webhook-Signature', '') expected = hmac.new(SECRET, payload, hashlib.sha256).hexdigest() if not hmac.compare_digest(expected, signature): abort(401) data = request.get_json() print(f"New email: {data['subject']} from {data['from']}") ``` -------------------------------- ### RSS Feed for an Email Address Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Generates an RSS 2.0 feed for a specified email address, allowing users to subscribe to email updates using any RSS reader. ```APIDOC ## GET /rss/[email] ### Description Returns an RSS 2.0 feed of all received emails for an address. Compatible with any RSS reader. ### Method GET ### Endpoint `/rss/[email]` ### Parameters #### Path Parameters - **email** (string) - Required - The email address for which to generate the RSS feed. ### Request Example ```bash curl http://localhost:8080/rss/test@example.com ``` ### Response #### Success Response (200) - **(XML)** - An RSS 2.0 formatted XML document containing email feed information. ### Response Example ```xml Open Trashmail - test@example.com Hello World Plain text body content Mon, 25 Apr 2024 12:00:00 +0000 ``` ``` -------------------------------- ### Save Webhook Configuration via API Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Use `curl` to send a POST request to the OpenTrashmail API to save webhook configuration for a specific email address. This includes enabling the webhook, setting the URL, payload template, retry attempts, and a secret key. ```bash curl -X POST http://localhost:8080/api/webhook/save/test@example.com \ -d "enabled=true" \ -d "webhook_url=https://myapi.com/webhook" \ -d 'payload_template={"email":"{{to}}","subject":"{{subject}}"}' \ -d "max_attempts=5" \ -d "secret_key=your-secret-key" ``` -------------------------------- ### Webhook Configuration - Save Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Saves or updates the webhook configuration for a specified email address. This endpoint likely accepts a request body with the webhook details. ```APIDOC ## Save Webhook Configuration ### Description Saves or updates the webhook configuration for a specific email address. ### Method POST ### Endpoint /api/webhook/save/[email-address] ### Parameters #### Path Parameters - **email-address** (string) - Required - The email address for which to save webhook configuration. ### Request Body (Details of the request body are not provided in the source, but would typically include webhook URL, event types, payload format, etc.) ``` -------------------------------- ### Verify Webhook Signature in PHP Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Use this PHP code to verify the HMAC-SHA256 signature of incoming webhook requests. Ensure your secret key is correctly configured and kept secure. ```php $payload = file_get_contents('php://input'); $signature = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? ''; $expected = hash_hmac('sha256', $payload, 'your-secret-key'); if (!hash_equals($expected, $signature)) { http_response_code(401); exit('Invalid signature'); } ``` -------------------------------- ### Delete Webhook Configuration Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Removes the webhook configuration for a specified email address. ```bash curl -X DELETE http://localhost:8080/api/webhook/delete/test@example.com ``` -------------------------------- ### Webhook Configuration - Delete Source: https://github.com/hascheksolutions/opentrashmail/blob/master/README.md Deletes the webhook configuration for a specified email address. ```APIDOC ## Delete Webhook Configuration ### Description Deletes the webhook configuration for a specific email address. ### Method DELETE ### Endpoint /api/webhook/delete/[email-address] ### Parameters #### Path Parameters - **email-address** (string) - Required - The email address for which to delete webhook configuration. ``` -------------------------------- ### HTML Body Only Source: https://context7.com/hascheksolutions/opentrashmail/llms.txt Extracts and returns only the HTML body content of an email, useful for rendering emails in a web view. ```APIDOC ## GET /api/raw-html/[email]/[id] ### Description Returns only the HTML body of an email. ### Method GET ### Endpoint `/api/raw-html/[email]/[id]` ### Parameters #### Path Parameters - **email** (string) - Required - The email address. - **id** (string) - Required - The unique identifier of the email. ### Request Example ```bash curl http://localhost:8080/api/raw-html/test@example.com/1714000000000 ``` ### Response #### Success Response (200) - **(text/html)** - The HTML content of the email body. ### Response Example ```html ...

Email HTML content with resolved inline images

... ``` ```