def mail_target_participants(participant_cls, target, subject, excluded_emails=[], template=None, **kwargs): """Send a message to participants of a given target.""" participants = participant_cls.objects.filter( content_type=ContentType.objects.get_for_model(target), object_id=target.pk, ) participants = [p for p in participants if p.email not in excluded_emails] messages = _get_messages(participants, template, **kwargs) mail_multiple_personalized(subject, messages, from_email=get_target_email_address(target))
def mail_facilitators(target, subject, excluded_emails=[], template='organize/notifications/facilitators_text.txt', **kwargs): """Sends a message to facilitators.""" facilitators = settings.FACILITATORS['global'] facilitators = [f for f in facilitators if f not in excluded_emails] messages = _get_facilitator_messages(facilitators, target, template, **kwargs) mail_multiple_personalized(subject, messages, fail_silently=False, from_email=get_target_email_address(target))
def mass_mailing(subject, message, objects, template_name, **kwargs): messages = {} for obj in objects: # message gets sent once to each unique email address, thanks to dict messages[obj.email] = render_to_string(template_name, { 'site': Site.objects.get_current(), 'target': obj.content_object, 'message': message, 'obj': obj, }) mail_multiple_personalized(subject, messages, **kwargs)