Skip to content

Instantly share code, notes, and snippets.

@emersonbarros
Created October 10, 2025 16:39
Show Gist options
  • Select an option

  • Save emersonbarros/dd44bbeccb04618d2bd1b04f79aaea73 to your computer and use it in GitHub Desktop.

Select an option

Save emersonbarros/dd44bbeccb04618d2bd1b04f79aaea73 to your computer and use it in GitHub Desktop.
import requests
import time
import re
# Define your Maildrop mailbox
mailbox_name = 'test-123' # Change to your desired mailbox
url = 'https://api.maildrop.cc/graphql'
headers = {'Content-Type': 'application/json'}
def query_maildrop_inbox(mailbox_name):
# Define the GraphQL query to get the inbox with date
query = '''
query {
inbox(mailbox: "%s") {
id
date
}
}
''' % mailbox_name
# Make the request
response = requests.post(url, headers=headers, json={'query': query})
if response.status_code == 200:
data = response.json()
return data['data']['inbox']
else:
print("Error accessing Maildrop:", response.status_code, response.text)
return None
def query_maildrop_message(mailbox_name, message_id):
# Define the GraphQL query to get the message details
query = '''
query {
message(mailbox: "%s", id: "%s") {
id
headerfrom
subject
date
html
}
}
''' % (mailbox_name, message_id)
# Make the request
response = requests.post(url, headers=headers, json={'query': query})
if response.status_code == 200:
data = response.json()
return data['data']['message']
else:
print("Error accessing Maildrop message:", response.status_code, response.text)
return None
def extract_verification_code(email_body):
# Use a regex to find the verification code
match = re.search(r'Código de verificación: (\d+)', email_body)
if match:
return match.group(1) # Capture the code
else:
return None
# Loop to check for emails
while True:
inbox = query_maildrop_inbox(mailbox_name)
if inbox:
# Sorting the inbox based on date in descending order (newest first)
sorted_inbox = sorted(inbox, key=lambda x: x['date'], reverse=True)
for email in sorted_inbox:
# Retrieve the message body using the message ID
message_id = email['id']
message = query_maildrop_message(mailbox_name, message_id)
if message:
# Get the HTML body
email_body = message.get('html', '')
verification_code = extract_verification_code(email_body)
if verification_code:
print(f'Code: {verification_code}')
else:
print('Verification code not found in the email body.')
else:
print('Message could not be retrieved.')
break # Exit after processing the emails
else:
print('No emails received, checking again in 10 seconds...')
time.sleep(10) # Wait 10 seconds before checking again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment