# Send an account activation email
self.backend.messages.send_template("auth/messages/register",
- recipients=[email], priority=100, uid=uid,
- activation_code=activation_code, email=email,
+ priority=100, uid=uid, activation_code=activation_code, email=email,
first_name=first_name, last_name=last_name)
def activate(self, uid, activation_code):
# Send a password reset email
self.backend.messages.send_template("auth/messages/password-reset",
- recipients=[self.email], priority=100, account=self, reset_code=reset_code)
+ priority=100, account=self, reset_code=reset_code)
def reset_password(self, reset_code, new_password):
# Delete the reset token
def bounce_email_address(self):
return self.settings.get("bounce_email_address")
- def _send(self, recipients, message, sender=None, priority=0):
- if not recipients:
- raise ValueError("Empty list of recipients")
-
- # Format recipients
- recipients = [self.make_recipient(r) for r in recipients]
-
- res = self.db.get("INSERT INTO messages(message, priority, envelope_recipients) \
- VALUES(%s, %s, %s) RETURNING id", message, priority, recipients)
+ def _send(self, message, sender=None, priority=0):
+ res = self.db.get("INSERT INTO messages(message, priority) \
+ VALUES(%s, %s) RETURNING id", message, priority)
logging.debug("Message queued with ID %s" % res.id)
- def send(self, recipients, message, priority=0, headers={}):
+ def send(self, message, priority=0, headers={}):
# Convert message from string
if not isinstance(message, email.message.Message):
message = email.message_from_string(message)
except KeyError:
message.add_header(k, v)
- # Read recipients from To: header
- if not recipients:
- recipients = message.get("To").split(", ")
-
# Add date if the message doesn't have one already
if "Date" not in message:
message.add_header("Date", email.utils.formatdate())
message.add_header("Errors-To", "<%s>" % self.bounce_email_address)
# Send the message
- self._send(recipients, message.as_string(), priority=priority)
+ self._send(message.as_string(), priority=priority)
- def send_template(self, template_name, recipients=[],
+ def send_template(self, template_name,
sender=None, priority=0, headers={}, **kwargs):
"""
Send a message based on the given template
message.attach(message_part)
# Send the message
- self.send(recipients, message, priority=priority, headers=headers)
+ self.send(message, priority=priority, headers=headers)
# In debug mode, re-compile the templates with every request
if self.backend.debug:
"post" : random.choice(posts),
}
- return self.send_template(template, recipients=[recipient,], **kwargs)
+ return self.send_template(template, **kwargs)
class Queue(misc.Object):
msg = email.message_from_string(message.message)
logging.debug("Sending a message %s to: %s" % (
- msg.get("Subject"), ", ".join(message.envelope_recipients)
+ msg.get("Subject"), msg.get("To"),
))
error_messages = []
# Try delivering the email
try:
- rejected_recipients = self.relay.send_message(msg,
- to_addrs=message.envelope_recipients)
+ rejected_recipients = self.relay.send_message(msg)
except smtplib.SMTPRecipientsRefused as e:
rejected_recipients = e.recipients