Created
June 6, 2024 19:48
-
-
Save nilsreichardt/a0840be589bf8fca90a7338b7153dd73 to your computer and use it in GitHub Desktop.
Get all email addresses rejected due to hard bounce. For Scaleway transaction emails
This file contains 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
import requests | |
import json | |
def fetch_emails(auth_token, output_file): | |
base_url = 'https://api.scaleway.com/transactional-email/v1alpha1/regions/fr-par/emails' | |
params = {'flags': 'hard_bounce', 'page': 0} | |
headers = {'X-Auth-Token': auth_token} | |
all_emails = [] | |
while True: | |
response = requests.get(base_url, headers=headers, params=params) | |
response_data = response.json() | |
if 'emails' not in response_data or not response_data['emails']: | |
break | |
for email_data in response_data['emails']: | |
all_emails.append(email_data['mail_rcpt']) | |
params['page'] += 1 | |
with open(output_file, 'w') as file: | |
json.dump(all_emails, file, indent=4) | |
if __name__ == "__main__": | |
AUTH_TOKEN = '...' # SCW_SECRET_KEY | |
OUTPUT_FILE = 'emails.json' | |
fetch_emails(AUTH_TOKEN, OUTPUT_FILE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment