Created
January 21, 2026 08:32
-
-
Save Zonalds/e87bfa74ff4bd45f2f340e80b151702a to your computer and use it in GitHub Desktop.
Python toggle on and send out warm email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| DitLead Email Warmup API Client | |
| ------------------------------- | |
| This script shows how to: | |
| 1) Enable or disable warming for a mailbox | |
| 2) Optionally enable manual warming mode | |
| 3) Trigger a manual warmup send | |
| Requirements: | |
| - 'requests' library installed | |
| - Replace placeholder values with real API key and mailbox info | |
| """ | |
| import requests | |
| # ---------------------------------- | |
| # CONFIGURATION | |
| # ---------------------------------- | |
| API_KEY = "YOUR_API_KEY" # Your DitLead API key | |
| BASE_URL = "https://api.ditlead.com/v1" # DitLead API base | |
| MAILBOX_EMAIL = "[email protected]" # The email address of the mailbox, required if MAILBOX_ID isn't provided. | |
| MAILBOX_ID = None # Optional: public mailbox ID (string) | |
| # ---------------------------------- | |
| # HEADERS | |
| # ---------------------------------- | |
| def headers(): | |
| """ | |
| Return the standard headers required for DitLead requests: | |
| - Authorization (Bearer token) | |
| - Content-Type (JSON) | |
| """ | |
| return { | |
| "Authorization": f"Bearer {API_KEY}", | |
| "Content-Type": "application/json" | |
| } | |
| # ---------------------------------- | |
| # 1. Toggle Warming ON/OFF | |
| # ---------------------------------- | |
| def toggle_warming(enable: bool, manual: bool): | |
| """ | |
| Enable or disable warming for a mailbox. | |
| :param enable: True to enable warming | |
| :param manual: True to enable manual warmup mode | |
| """ | |
| url = f"{BASE_URL}/mailbox/warming" | |
| payload = { | |
| "mailboxAddress": MAILBOX_EMAIL, | |
| "warming": enable, | |
| "manualWarming": manual | |
| } | |
| response = requests.post(url, json=payload, headers=headers()) | |
| if response.ok: | |
| print(f"Warming {'enabled' if enable else 'disabled'} (manual={manual})") | |
| print(response.json()) | |
| else: | |
| print("Error toggling warming:", response.status_code, response.text) | |
| # ---------------------------------- | |
| # 2. Trigger Manual Warming Send | |
| # ---------------------------------- | |
| def send_manual_warmup(): | |
| """ | |
| Trigger a manual warmup send for a mailbox. | |
| This only works if manual warming has been enabled and | |
| the daily send limit has not been reached. | |
| """ | |
| url = f"{BASE_URL}/mailbox/warming/send" | |
| payload = {} | |
| # You must send either mailboxId OR mailboxAddress | |
| if MAILBOX_ID: | |
| payload["mailboxId"] = MAILBOX_ID | |
| else: | |
| payload["mailboxAddress"] = MAILBOX_EMAIL | |
| response = requests.post(url, json=payload, headers=headers()) | |
| if response.ok: | |
| print("Manual warmup send triggered successfully.") | |
| print(response.json()) | |
| else: | |
| print("Error triggering manual warmup:", response.status_code, response.text) | |
| # ---------------------------------- | |
| # EXAMPLE USAGE | |
| # ---------------------------------- | |
| if __name__ == "__main__": | |
| # 1️⃣ Turn on warming and enable manual warmup mode | |
| toggle_warming(enable=True, manual=True) | |
| # 2️⃣ Trigger a manual send | |
| send_manual_warmup() | |
| # 3️⃣ Later, you can disable warming (manual or automatic) | |
| # toggle_warming(enable=False, manual=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment