def send(self, recipients): """Attempt to send the email. This may be called on emails that have already been sent. recipients: A sequence of Visitor objects who will be sent this message. """ if not recipients or not recipients.exists(): return urlbase = app_settings.URLBASE einstantiator = _email.email_instantiator(self.txtmsg, self.htmlmsg, urlbase) # Note: msgs = list of django.core.mail.EmailMultiAlternatives msgs = [] cx = mail.get_connection() # Build the emails for recipient in recipients: i = TrackedInstance(tracker=self.tracker, visitor=recipient) i.save() text, html = einstantiator(i.uuid) msg = self._create_multipart_email(text, html, recipient, cx) msgs.append((msg, i, recipient,)) rs = [] # recipients to whom the email was sent today = datetime.date.today() # Send the emails cx.open() try: for msg, i, rec in msgs: msg.send() i.notified = today i.save() rs.append(rec) finally: cx.close() # Close the connection! # Record the recipients er = EmailRecipients(email=self, datesent=today) er.save() for recipient in rs: er.recipients.add(recipient) er.save()