def email_member(notice, membership, global_context):
            corp_profile = membership.corp_profile
            representatives = corp_profile.reps.filter(Q(is_dues_rep=True)|(Q(is_member_rep=True)))
            sent = 0

            corp_app = CorpMembershipApp.objects.current_app()
            authentication_info = render_to_string(
                'notification/corp_memb_notice_email/auth_info.html',
                {'corp_membership': membership,
                 'corp_app': corp_app})
            individuals_join_url = '%s%s' % (site_url,
                                             reverse('membership_default.corp_pre_add',
                                                     args=[membership.id]))
            if membership.expiration_dt:
                expire_dt = time.strftime("%d-%b-%y %I:%M %p",
                                          membership.expiration_dt.timetuple())
            else:
                expire_dt = ''

            if membership.payment_method:
                payment_method = membership.payment_method.human_name
            else:
                payment_method = ''

            if membership.renewal:
                renewed_individuals_list = render_to_string(
                    'notification/corp_memb_notice_email/renew_list.html',
                    {'corp_membership': membership})
                total_individuals_renewed = membership.indivmembershiprenewentry_set.count()
            else:
                renewed_individuals_list = ''
                total_individuals_renewed = ''

            if membership.invoice:
                invoice_link = '%s%s' % (site_url,
                                         membership.invoice.get_absolute_url())
            else:
                invoice_link = ''

            global_context.update({
                'name': corp_profile.name,
                'email': corp_profile.email,
                'expire_dt': expire_dt,
                'payment_method': payment_method,
                'renewed_individuals_list': renewed_individuals_list,
                'total_individuals_renewed': total_individuals_renewed,
                'view_link': "%s%s" % (site_url, membership.get_absolute_url()),
                'renew_link': "%s%s" % (site_url, membership.get_renewal_url()),
                'invoice_link': invoice_link,
                'authentication_info': authentication_info,
                'individuals_join_url': individuals_join_url,
            })

            for recipient in representatives:
                body = notice.email_content
                context = membership.get_field_items()
                context['membership'] = membership
                context.update(global_context)

                context.update({
                    'rep_first_name': recipient.user.first_name,
                })

                body = fieldify(body)

                body = '%s <br /><br />%s' % (body, get_footer())

                context = Context(context)
                template = Template(body)
                body = template.render(context)

                email_recipient = recipient.user.email
                subject = notice.subject.replace('(name)',
                                            corp_profile.name)
                template = Template(subject)
                subject = template.render(context)

                email_context.update({
                    'subject':subject,
                    'content':body})

                if notice.sender:
                    email_context.update({
                        'sender':notice.sender,
                        'reply_to':notice.sender})
                if notice.sender_display:
                    email_context.update({'sender_display':notice.sender_display})

                notification.send_emails([email_recipient], 'corp_memb_notice_email',
                                         email_context)
                sent += 1
                if verbosity > 1:
                    print 'To ', email_recipient, subject
            return sent
        def email_member(notice, membership, global_context):
            user = membership.user

            body = notice.email_content
            context = membership.get_field_items()
            context['membership'] = membership
            context.update(global_context)

            # corporate member corp_replace_str
            if membership.corporate_membership_id:
                context['corporate_membership_notice'] = corp_replace_str

            if membership.expire_dt:
                context.update({
                    'expire_dt':
                    time.strftime("%d-%b-%y %I:%M %p",
                                  membership.expire_dt.timetuple()),
                })

            if membership.payment_method:
                payment_method_name = membership.payment_method.human_name
            else:
                payment_method_name = ''

            context.update({
                'member_number':
                membership.member_number,
                'payment_method':
                payment_method_name,
                'referer_url':
                '%s%s?next=%s' %
                (site_url, reverse('auth_login'), membership.referer_url),
                'membership_link':
                '%s%s' % (site_url, membership.get_absolute_url()),
                'view_link':
                '%s%s' % (site_url, membership.get_absolute_url()),
                'renew_link':
                '%s%s' % (site_url, membership.get_absolute_url()),
                'mymembershipslink':
                '%s%s' % (site_url, membership.get_absolute_url()),
                'membershiplink':
                '%s%s' % (site_url, membership.get_absolute_url()),
                'renewlink':
                '%s%s' % (site_url, membership.get_absolute_url())
            })

            body = fieldify(body)

            body = body + ' <br /><br />{% include "email_footer.html" %}'

            template = engines['django'].from_string(body)
            body = template.render(context=context)

            email_recipient = user.email
            subject = notice.subject.replace('(name)', user.get_full_name())
            template = engines['django'].from_string(subject)
            subject = template.render(context=context)

            email_context.update({'subject': subject, 'content': body})
            if notice.sender:
                email_context.update({
                    #'sender':notice.sender,
                    'reply_to': notice.sender
                })
            if notice.sender_display:
                email_context.update({'sender_display': notice.sender_display})

            notification.send_emails([email_recipient],
                                     'membership_notice_email', email_context)
            if verbosity > 1:
                print('To ', email_recipient, subject)
        def email_member(notice, membership, global_context):
            user = membership.user

            body = notice.email_content
            context = membership.get_field_items()
            context['membership'] = membership
            context.update(global_context)

            # corporate member corp_replace_str
            if membership.corporate_membership_id:
                context['corporate_membership_notice'] = corp_replace_str

            if membership.expire_dt:
                context.update({
                    'expire_dt': time.strftime(
                    "%d-%b-%y %I:%M %p",
                    membership.expire_dt.timetuple()),
                })

            if membership.payment_method:
                payment_method_name = membership.payment_method.human_name
            else:
                payment_method_name = ''

            context.update({
                'member_number': membership.member_number,
                'payment_method': payment_method_name,
                'referer_url': '%s%s?next=%s' % (site_url, reverse('auth_login'), membership.referer_url),
                'membership_link': '%s%s' % (site_url, membership.get_absolute_url()),
                'renew_link': '%s%s' % (site_url, membership.get_absolute_url()),
                'mymembershipslink': '%s%s' % (site_url, membership.get_absolute_url()),
                'membershiplink': '%s%s' % (site_url, membership.get_absolute_url()),
                'renewlink': '%s%s' % (site_url, membership.get_absolute_url())
            })

            body = fieldify(body)

            body = '%s <br /><br />%s' % (body, get_footer())

            context = Context(context)
            template = Template(body)
            body = template.render(context)

            email_recipient = user.email
            subject = notice.subject.replace('(name)',
                                        user.get_full_name())
            template = Template(subject)
            subject = template.render(context)

            email_context.update({
                'subject':subject,
                'content':body})
            if notice.sender:
                email_context.update({
                    #'sender':notice.sender,
                    'reply_to':notice.sender})
            if notice.sender_display:
                email_context.update({'sender_display':notice.sender_display})

            notification.send_emails([email_recipient], 'membership_notice_email',
                                     email_context)
            if verbosity > 1:
                print 'To ', email_recipient, subject