Created
April 28, 2013 16:55
-
-
Save danielrichman/5477482 to your computer and use it in GitHub Desktop.
Check that email is actually delivered
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
#!/usr/bin/python | |
import time | |
from subprocess import Popen, PIPE | |
from email.mime.text import MIMEText | |
from email import message_from_string | |
from poplib import POP3_SSL | |
emails = [ | |
('[email protected]', 'pop.mail.yahoo.com'), | |
('[email protected]', 'pop3.live.com'), | |
('[email protected]', 'pop.aol.com') | |
] | |
email_from = 'postmaster@DOMAIN' | |
subject = time.strftime("%Y-%m-%d %H:%M:%S") + " Deliverability Test" | |
msg = MIMEText("Email deliverability testing") | |
msg['Subject'] = subject | |
msg['From'] = email_from | |
for to, pop in emails: | |
del msg['To'] | |
msg['To'] = to | |
p = Popen(["/usr/sbin/sendmail", "-t"], stdin=PIPE) | |
p.stdin.write(msg.as_string()) | |
p.stdin.close() | |
p.wait() | |
assert p.returncode == 0 | |
success = set() | |
start = time.time() | |
wait_cumulative = 0 | |
for wait in [1] * 10 + [10] * 5 + [60] * 9 + [600] * 11: | |
wait_cumulative += wait | |
time.sleep(max(start + wait_cumulative - time.time(), 0)) | |
for email, receive in set(emails) - success: | |
p = POP3_SSL(receive, 995) | |
p.user(email) | |
p.pass_("PASSWORD") | |
messages = range(1, len(p.list()[1]) + 1) | |
for i in messages: | |
lines = p.retr(i)[1] | |
rmsg = message_from_string("\n".join(lines)) | |
if subject in rmsg['Subject']: | |
success.add((email, receive)) | |
# print email, "succeeded after", wait_cumulative, "seconds" | |
for i in messages: | |
p.dele(i) | |
p.quit() | |
if set(emails) - success == set(): | |
break | |
else: | |
print "Gave up on checking these inboxes for", subject | |
print "After", wait_cumulative, "seconds" | |
for email, receive in set(emails) - success: | |
print email |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: check if it ended up in the spam folder;
Test more providers