def emailUser(profile, SUBJECT='', BODY=''):
 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

def emailUser ( profile , SUBJECT = '' , BODY = '' ) : def generateSMSEmail ( profile ) : 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
sends an email .