Keeping DRY with sending mail in Django
I have the following two blocks of code in a LOT of my views. Im looking for a way to abstract them so that instead of repeating this code in every view. The receipent, subject line and body will vary of course, so I would like to be able to pass those strings to this function--"function" is the right term to use, correct?

    mailt = loader.get_template('membership/signup_email.txt')
    mailc = Context({
        'signin_url': signin_url,
        'name': firstname + ' ' + lastname,
        'username': username,
        'membership_level': membership_level.name,
        'membership_number': membership_number,
        'payment_plan': payment_plan
    })
    msg = EmailMessage(
        'You are now a Member!',
        mailt.render(mailc),
        'membership@domain.org',
        [email]
    )
    msg.content_subtype = "html"
    msg.send()

    # Nofity our staff
    admin_mailt = loader.get_template('membership/signup_admin_email.txt')
    admin_mailc = Context({
        'site': current_site,
        'user': user,
        'payment_plan': payment_plan
    })
    admin_msg = EmailMessage(
        '[myproject] New Membership Signup',
        admin_mailt.render(admin_mailc),
        'membership@domain.org',
        ['membership@domain.org']
    )
    admin_msg.content_subtype = "html"
    admin_msg.send()
Keeping DRY with sending mail in Django
===

I have the following two blocks of code in a LOT of my views. Im looking for a way to abstract them so that instead of repeating this code in every view. The receipent, subject line and body will vary of course, so I would like to be able to pass those strings to this function--"function" is the right term to use, correct?

    mailt = loader.get_template('membership/signup_email.txt')
    mailc = Context({
        'signin_url': signin_url,
        'name': firstname + ' ' + lastname,
        'username': username,
        'membership_level': membership_level.name,
        'membership_number': membership_number,
        'payment_plan': payment_plan
    })
    msg = EmailMessage(
        'You are now a Member!',
        mailt.render(mailc),
        'membership@domain.org',
        [email]
    )
    msg.content_subtype = "html"
    msg.send()

    # Nofity our staff
    admin_mailt = loader.get_template('membership/signup_admin_email.txt')
    admin_mailc = Context({
        'site': current_site,
        'user': user,
        'payment_plan': payment_plan
    })
    admin_msg = EmailMessage(
        '[myproject] New Membership Signup',
        admin_mailt.render(admin_mailc),
        'membership@domain.org',
        ['membership@domain.org']
    )
    admin_msg.content_subtype = "html"
    admin_msg.send()