use render to check verification email subject
-from django.core.mail.backends.smtp import EmailBackend
-from django.core.mail.backends.console import EmailBackend as consoleBackend
+from smtplib import SMTP
+from django.core.mail.backends.smtp import EmailBackend as SmtpBackend
+from django.core.mail.backends.console import EmailBackend as ConsoleBackend
from django.contrib.sites.models import Site
from django.core.exceptions import ImproperlyConfigured
+from django.template.loader import render_to_string
-class BetaEmailBackend(EmailBackend):
+class BetaEmailBackend(ConsoleBackend):
def send_messages(self, email_messages):
"""
Beta Hydroshare specific email backend
@@ -21,21 +23,18 @@ class BetaEmailBackend(EmailBackend):
)
if not email_messages:
return 0
- with self._lock:
- new_conn_created = self.open()
- if not self.connection or new_conn_created is None:
- # We failed silently on open().
- # Trying to send would be pointless.
- return 0
num_sent = 0
+
for message in email_messages:
# TODO: are there any other emails that beta HS should actually send?
- if message.subject == "Activate your account in HydroShare":
- sent = self._send(message)
+ activation_subject = render_to_string('email/signup_verify_subject.txt')
+ if not message.subject in activation_subject:
+ sent = self.write_message(message)
if sent:
- num_sent += 1
+ num_sent += sent
else:
- num_sent += consoleBackend.send_messages(message)
- if new_conn_created:
- self.close()
+ smtp_email_backend = SmtpBackend()
+ sent = smtp_email_backend.send_messages(message)
+ if sent:
+ num_sent += sent
return num_sent
