예제 #1
0
def add_user_to_global_list(email):
    """ add user to email list that gets all emails """
    signup_db = db.UserSignup.objects.get(email=email,
                                          date_deleted__isnull=True)
    if signup_db.sequence:
        list_name = sequence_model.sequence_list_name(signup_db.sequence)
        mailgun_api.add_list_member(list_name, email)
예제 #2
0
def send_email( email_uri ):
    """ Send the email to the intended target audience """
    email = mail_api.get_email(email_uri)

    if email['audience'] == 'groups':
        to_addresses = [g['address'] for g in group_api.get_groups(email['sequence'])]
    elif email['audience'] == 'individuals':
        to_addresses = [sequence_api.sequence_list_name(email['sequence'])]

    text_body = render_to_string('mail/email.txt', {'email': email})
    html_body = render_to_string('mail/email.html', {'email': email})

    batch_size = 1000

    for i in range(0, len(to_addresses), batch_size):
        mailgun_api.send_mass_email(
            to_addresses[i:i+batch_size],
            settings.DEFAULT_FROM_EMAIL,
            email['subject'],
            text_body,
            html_body,
            email['tags'].split(','),
            sequence_api.sequence_campaign(email['sequence'])
        )
    mail_api.mark_sent(email_uri)
예제 #3
0
def add_user_to_global_list( email, sequence ):
    """ add user to email list that gets all emails """
    signup_db = db.UserSignup.objects.get(
        email__iexact=email, date_deleted__isnull=True, sequence=sequence
    )
    if signup_db.sequence:
        list_name = sequence_model.sequence_list_name(signup_db.sequence)
        mailgun_api.add_list_member(list_name, email)
예제 #4
0
def send_email(email_uri):
    """ Send the email to the intended target audience """
    email = mail_api.get_email(email_uri)

    if email['audience'] == 'groups':
        to_address = ','.join(
            [g['address'] for g in group_api.get_groups(email['sequence'])])
    elif email['audience'] == 'individuals':
        to_address = sequence_api.sequence_list_name(email['sequence'])

    text_body = render_to_string('mail/email.txt', {'email': email})
    html_body = render_to_string('mail/email.html', {'email': email})

    mailgun_api.send_email(to_address, settings.DEFAULT_FROM_EMAIL,
                           email['subject'], text_body, html_body,
                           email['tags'].split(','),
                           sequence_api.sequence_campaign(email['sequence']))
    mail_api.mark_sent(email_uri)
예제 #5
0
def unsubscribe_from_sequence( address ):

    # remove from sequence group
    try:
        user_signup = signup_model.get_signup(address)
        sequence_list = sequence_model.sequence_list_name(user_signup['sequence'])
        mailgun_api.remove_list_member(sequence_list, address)
    except:
        log.error(u"couldn't remove {0} from sequence list".format(address))
    
    # remove from small groups
    # TODO: Can a user be subscribed to more than one group or more than one
    # sequence at the same time?
    groups = groups_model.get_member_groups(address)
    for group in groups:
        groups_model.remove_group_member(group['uri'], address)
        groups_model.sync_group_with_mailgun(group['uri'])

    # add signup to next sequence.
    signup_model.remove_signup_from_sequence(address)
예제 #6
0
def unsubscribe_user( address ):
    """ Unsubscribe user completely from the Mechanical Mooc 
    """

    # remove from sequence group
    try:
        user_signup = signup_model.get_signup(address)
        sequence_list = sequence_model.sequence_list_name(user_signup['sequence'])
        mailgun_api.remove_list_member(sequence_list, address)
    except:
        log.error(u"couldn't remove {0} from sequence list".format(address))

    # remove from small groups
    groups = groups_model.get_member_groups(address)
    for group in groups:
        groups_model.remove_group_member(group['uri'], address)
        groups_model.sync_group_with_mailgun(group['uri'])

    # mark as unsubscribed in the signups
    signup_model.delete_signup(address)
예제 #7
0
def unsubscribe_user(address):
    """ Unsubscribe user completely from the Mechanical Mooc - all sequences
    """

    # remove from sequence group
    signups = signup_model.get_all_user_signups(address)
    for user_signup in signups:
        sequence_list = sequence_model.sequence_list_name(user_signup["sequence"])
        mailgun_api.remove_list_member(sequence_list, address)

    # remove from small groups
    groups = groups_model.get_member_groups(address)
    for group in groups:
        groups_model.remove_group_member(group["uri"], address)
        groups_model.sync_group_with_mailgun(group["uri"])

    # mark as unsubscribed in the signups
    for user_signup in signups:
        signup_model.delete_signup(address, user_signup["sequence"])

    mailgun_api.delete_all_unsubscribes(address)
예제 #8
0
def unsubscribe_user(address):
    """ Unsubscribe user completely from the Mechanical Mooc - all sequences
    """

    # remove from sequence group
    signups = signup_model.get_all_user_signups(address)
    for user_signup in signups:
        sequence_list = sequence_model.sequence_list_name(
            user_signup['sequence'])
        mailgun_api.remove_list_member(sequence_list, address)

    # remove from small groups
    groups = groups_model.get_member_groups(address)
    for group in groups:
        groups_model.remove_group_member(group['uri'], address)
        groups_model.sync_group_with_mailgun(group['uri'])

    # mark as unsubscribed in the signups
    for user_signup in signups:
        signup_model.delete_signup(address, user_signup['sequence'])

    mailgun_api.delete_all_unsubscribes(address)
예제 #9
0
def send_email( email_uri ):
    """ Send the email to the intended target audience """
    email = mail_api.get_email(email_uri)

    if email['audience'] == 'groups':
        to_address = ','.join([g['address'] for g in group_api.get_groups(email['sequence'])])
    elif email['audience'] == 'individuals':
        to_address = sequence_api.sequence_list_name(email['sequence'])

    text_body = render_to_string('mail/email.txt', {'email': email})
    html_body = render_to_string('mail/email.html', {'email': email})

    mailgun_api.send_email(
        to_address,
        settings.DEFAULT_FROM_EMAIL,
        email['subject'],
        text_body,
        html_body,
        email['tags'].split(','),
        sequence_api.sequence_campaign(email['sequence'])
    )
    mail_api.mark_sent(email_uri)