human
Complete this python program:
def emailUser(profile, SUBJECT='', BODY=''):
assistant
#Here is the Python code you requested.

    """sends an email.
    Arguments:
    profile -- contains information related to the user (e.g., email
    address)
    SUBJECT -- subject line of the email
    BODY -- body text of the email
    """
    def generateSMSEmail(profile):
        "\n                                Generates    an    email    from    a    user's    phone    number    based    on    their    carrier.\n                                "
        if ((profile['carrier'] is None) or (not profile['phone_number'])):
            return None
        return ((str(profile['phone_number']) + '@') + profile['carrier'])
    if (profile['prefers_email'] and profile['gmail_address']):
        if BODY:
            BODY = ((profile['first_name'] + ',<br><br>Here    are    your    top    headlines:') + BODY)
            BODY += '<br>Sent    from    your    Jasper'
        recipient = profile['gmail_address']
        if (profile['first_name'] and profile['last_name']):
            recipient = (((profile['first_name'] + '    ') + profile['last_name']) + ('    <%s>' % recipient))
    else:
        recipient = generateSMSEmail(profile)
    if (not recipient):
        return False
    try:
        if ('mailgun' in profile):
            user = profile['mailgun']['username']
            password = profile['mailgun']['password']
            server = 'smtp.mailgun.org'
        else:
            user = profile['gmail_address']
            password = profile['gmail_password']
            server = 'smtp.gmail.com'
        sendEmail(SUBJECT, BODY, recipient, user, 'Jasper    <jasper>', password, server)
        return True
    except:
        return False