Refs #127 -- Go even further with SMTP testing

This commit is contained in:
Raphael Michel
2016-03-10 21:18:51 +01:00
parent 49aa28bf80
commit 6f235f4b18
3 changed files with 30 additions and 11 deletions

21
src/pretix/base/email.py Normal file
View File

@@ -0,0 +1,21 @@
from smtplib import SMTPRecipientsRefused, SMTPSenderRefused
from django.core.mail.backends.smtp import EmailBackend
class CustomSMTPBackend(EmailBackend):
def test(self, from_addr):
try:
self.open()
self.connection.ehlo_or_helo_if_needed()
self.connection.rcpt("test@example.org")
(code, resp) = self.connection.mail(from_addr, [])
if code != 250:
raise SMTPSenderRefused(code, resp, from_addr)
senderrs = {}
(code, resp) = self.connection.rcpt('')
if (code != 250) and (code != 251):
raise SMTPRecipientsRefused(senderrs)
finally:
self.close()