-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_flags_request.py
More file actions
executable file
·226 lines (180 loc) · 6.96 KB
/
send_flags_request.py
File metadata and controls
executable file
·226 lines (180 loc) · 6.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/usr/bin/env python3
"""
Embassy Flag Request Script
Sends personalized flag request emails to embassies worldwide
"""
import json
import smtplib
import time
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from pathlib import Path
from typing import List, Dict
import logging
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler('embassy_emails.log'),
logging.StreamHandler()
]
)
class EmbassyEmailer:
"""Handle sending flag request emails to embassies"""
def __init__(self, smtp_server: str, smtp_port: int, email: str, password: str):
"""
Initialize the emailer
Args:
smtp_server: SMTP server address (e.g., 'mail.protonmail.com')
smtp_port: SMTP port (e.g., 587 for TLS)
email: Your ProtonMail email address
password: Your ProtonMail password or app password
"""
self.smtp_server = smtp_server
self.smtp_port = smtp_port
self.email = email
self.password = password
self.template = self._load_template()
def _load_template(self) -> str:
"""Load the email template from file"""
template_path = Path(__file__).parent / 'email_template.txt'
with open(template_path, 'r', encoding='utf-8') as f:
return f.read()
def _load_embassies(self, list_type: str = 'public') -> List[Dict]:
"""
Load embassy list from JSON file
Args:
list_type: 'public' or 'private' embassy list
"""
if list_type == 'private':
embassies_path = Path(__file__).parent / 'embassies_private.json'
else:
embassies_path = Path(__file__).parent / 'embassies_public.json'
with open(embassies_path, 'r', encoding='utf-8') as f:
return json.load(f)
def _personalize_email(self, country: str) -> tuple:
"""
Personalize the email template for a specific country
Args:
country: Name of the country
Returns:
Tuple of (subject, body)
"""
# Extract subject from template
lines = self.template.split('\n')
subject_line = lines[0].replace('Subject: ', '')
body_lines = lines[1:] # Skip the subject line
# Replace country placeholders
subject = subject_line.replace('{{COUNTRY}}', country)
body = '\n'.join(body_lines).replace('{{COUNTRY}}', country)
return subject, body
def send_email(self, to_email: str, country: str) -> bool:
"""
Send a flag request email to an embassy
Args:
to_email: Embassy email address
country: Country name
Returns:
True if successful, False otherwise
"""
try:
subject, body = self._personalize_email(country)
# Create message
msg = MIMEMultipart()
msg['From'] = self.email
msg['To'] = to_email
msg['Subject'] = subject
# Attach body
msg.attach(MIMEText(body, 'plain'))
# Connect and send
with smtplib.SMTP(self.smtp_server, self.smtp_port) as server:
server.starttls()
server.login(self.email, self.password)
server.send_message(msg)
logging.info(f"✓ Successfully sent email to {country} ({to_email})")
return True
except Exception as e:
logging.error(f"✗ Failed to send email to {country} ({to_email}): {str(e)}")
return False
def send_bulk_emails(self, delay: int = 5, test_mode: bool = False, list_type: str = 'public'):
"""
Send emails to all embassies in the list
Args:
delay: Seconds to wait between emails (to avoid rate limiting)
test_mode: If True, only send to first 3 embassies
list_type: 'public' or 'private' embassy list
"""
embassies = self._load_embassies(list_type)
if test_mode:
embassies = embassies[:3]
logging.info("Running in TEST MODE - only sending to first 3 embassies")
total = len(embassies)
successful = 0
failed = 0
logging.info(f"Starting to send emails to {total} embassies...")
for i, embassy in enumerate(embassies, 1):
country = embassy['country']
email = embassy['email']
logging.info(f"[{i}/{total}] Sending to {country}...")
if self.send_email(email, country):
successful += 1
else:
failed += 1
# Wait between emails to avoid rate limiting
if i < total:
logging.info(f"Waiting {delay} seconds before next email...")
time.sleep(delay)
logging.info("=" * 50)
logging.info(f"Email campaign completed!")
logging.info(f"Total: {total} | Successful: {successful} | Failed: {failed}")
logging.info("=" * 50)
def main():
"""Main entry point for the script"""
print("=" * 60)
print("Embassy Flag Request Email Sender")
print("=" * 60)
print()
# Configuration
print("Please enter your ProtonMail credentials:")
email = input("ProtonMail email address: ").strip()
password = input("ProtonMail password (or app password): ").strip()
print()
print("SMTP Configuration:")
print("1. ProtonMail (mail.protonmail.com)")
print("2. ProtonMail Bridge (127.0.0.1) - for desktop client")
print("3. Custom SMTP server")
choice = input("Select option (1-3): ").strip()
if choice == "1":
smtp_server = "mail.protonmail.com"
smtp_port = 587
elif choice == "2":
smtp_server = "127.0.0.1"
smtp_port = 1025
else:
smtp_server = input("SMTP server address: ").strip()
smtp_port = int(input("SMTP port: ").strip())
print()
print("Embassy list type:")
print("1. Public list (all countries)")
print("2. Private list (excludes Taiwan, Netherlands, Russia)")
list_choice = input("Select list (1-2): ").strip()
list_type = 'private' if list_choice == '2' else 'public'
print()
test_mode = input("Run in TEST mode? (only send to 3 embassies) [y/N]: ").strip().lower() == 'y'
if not test_mode:
print()
print("⚠️ WARNING: This will send emails to ~190 embassies!")
confirm = input("Are you sure you want to continue? [y/N]: ").strip().lower()
if confirm != 'y':
print("Cancelled.")
return
delay = int(input("Delay between emails (seconds, recommended 5-10): ").strip() or "5")
print()
print("Starting email campaign...")
print()
# Create emailer and send
emailer = EmbassyEmailer(smtp_server, smtp_port, email, password)
emailer.send_bulk_emails(delay=delay, test_mode=test_mode, list_type=list_type)
if __name__ == "__main__":
main()