Exemplo n.º 1
0
def router(sender, **kwargs):
    # Pull our email object and convert it to the mailgun_data we need`
    email = kwargs['instance']
    mailgun_data = email.get_mailgun_data(stripped=True, footer=True)
    logger.debug("In Router: ")
    logger.debug(mailgun_data)

    # Pull our attachments and convert it to the list of files we need
    attachments = kwargs['attachments']
    files = []
    for a in attachments:
        files.append(('attachment', open(a.file.path)))

    # Build out the BCC depending on who the recipient is
    bcc_list = None
    mailing_list = SimpleMailingList.objects.filter(address=email.recipient).first()
    if mailing_list:
        bcc_list = mailing_list.get_subscriber_list()
    elif hasattr(settings, "STAFF_EMAIL_ADDRESS") and email.recipient == settings.STAFF_EMAIL_ADDRESS:
        bcc_list = list(User.objects.filter(is_staff=True, is_active=True).values_list('email', flat=True))
    elif hasattr(settings, "TEAM_EMAIL_ADDRESS") and email.recipient == settings.TEAM_EMAIL_ADDRESS:
        bcc_list = list(User.helper.managers(include_future=True).values_list('email', flat=True))
    logger.debug("BCC List:")
    logger.debug(bcc_list)

    if bcc_list:
        # Pass this message along
        mailgun_data["bcc"] = bcc_list
        mailgun.mailgun_send(mailgun_data, files)
Exemplo n.º 2
0
def router(sender, **kwargs):
    # Pull our email object and convert it to the mailgun_data we need`
    email = kwargs['instance']
    strip_emails = getattr(settings, "COMLINK_STRIP_EMAILS", False)
    mailgun_data = email.get_mailgun_data(stripped=strip_emails, footer=True)
    logger.debug("In Router: ")
    logger.debug(mailgun_data)

    # Pull our attachments and convert it to the list of files we need
    attachments = kwargs['attachments']
    files = []
    for a in attachments:
        files.append(('attachment', open(a.file.path, mode='rb')))

    # Build out the BCC depending on who the recipient is
    bcc_list = None
    mailing_list = SimpleMailingList.objects.filter(
        address=email.recipient).first()
    if mailing_list:
        bcc_list = mailing_list.get_subscriber_list()
    elif hasattr(settings, "STAFF_EMAIL_ADDRESS"
                 ) and settings.STAFF_EMAIL_ADDRESS in email.recipient:
        bcc_list = list(
            User.objects.filter(is_staff=True,
                                is_active=True).values_list('email',
                                                            flat=True))
    elif hasattr(settings, "TEAM_EMAIL_ADDRESS"
                 ) and settings.TEAM_EMAIL_ADDRESS in email.recipient:
        bcc_list = list(
            User.helper.managers(include_future=True).values_list('email',
                                                                  flat=True))
    logger.debug("BCC List:")
    logger.debug(bcc_list)

    if bcc_list:
        # Pass this message along
        mailgun_data["bcc"] = bcc_list
        mailgun.mailgun_send(mailgun_data, files)
Exemplo n.º 3
0
def send_manage_member(user, subject=None):
    if subject == None:
        subject = "Incomplete Tasks"
    subject = "%s - %s" % (subject, user.get_full_name())
    if hasattr(settings, "EMAIL_SUBJECT_PREFIX"):
        # Adjust the subject if we have a prefix
        subject = settings.EMAIL_SUBJECT_PREFIX.strip() + " " + subject.strip()

    text_content, html_content = get_manage_member_content(user)
    mailgun_data = {
        "from": settings.DEFAULT_FROM_EMAIL,
        "to": [settings.TEAM_EMAIL_ADDRESS, ],
        "subject": subject,
        "text": text_content,
        "html": html_content,
    }
    return mailgun.mailgun_send(mailgun_data, inject_list_id=False)
Exemplo n.º 4
0
def send_manage_member(user, subject=None):
    if subject == None:
        subject = "Incomplete Tasks"
    subject = "%s - %s" % (subject, user.get_full_name())
    if hasattr(settings, "EMAIL_SUBJECT_PREFIX"):
        # Adjust the subject if we have a prefix
        subject = settings.EMAIL_SUBJECT_PREFIX.strip() + " " + subject.strip()

    text_content, html_content = get_manage_member_content(user)
    mailgun_data = {
        "from": settings.DEFAULT_FROM_EMAIL,
        "to": [settings.TEAM_EMAIL_ADDRESS, ],
        "subject": subject,
        "text": text_content,
        "html": html_content,
    }
    if hasattr(settings, 'MAILGUN_DOMAIN'):
        return mailgun.mailgun_send(mailgun_data, inject_list_id=False)