def send_subject_request_mail_new(sender, instance=None, **kwargs): """Send en email when a subject request is created.""" if not instance or not kwargs['created']: return subject = "%s requested: %s" % (instance.user, str(instance)) to = stock_managers_emails() alyx_mail(to, subject, instance.description)
def _send(self, to, subject, text=''): self.stdout.write('"%s" to be sent to <%s>.\n\n' % (subject, to)) self.stdout.write(text) self.stdout.write("\n\n") # NOTE: if there is no '*', it means the email is empty, so we don't send it. if to and self.do_send and '*' in text: alyx_mail(to, subject, text) elif self.do_send and '*' not in text: logger.debug("NOT sending an empty email.")
def send_subject_request_mail_change(sender, instance=None, **kwargs): """Send en email when a subject's request changes.""" if not instance: return # Only continue if the request has changed. if not (_get_current_field(instance, 'request') is not None and _get_old_field(instance, 'request') is None): return # Only continue if there's an email. if not instance.responsible_user.email: return subject = ("Subject %s was assigned to you for request %s" % (instance.nickname, str(instance.request))) alyx_mail(instance.responsible_user.email, subject)
def send_if_needed(self): """Send the email if needed and change the status to 'sent'""" if self.status == 'sent': logger.warning("Email already sent at %s.", self.sent_at) return False if not self.ready_to_send(): logger.warning("Email not ready to send.") return False emails = [user.email for user in self.users.all() if user.email] if alyx_mail(emails, self.title, self.message): self.status = 'sent' self.sent_at = timezone.now() self.save() return True