def enroll_email(course_id, student_email, auto_enroll=False, email_students=False, email_params=None, language=None):
 previous_state = EmailEnrollmentState(course_id, student_email)
 enrollment_obj = None
 if previous_state.user:
  if CourseMode.is_white_label(course_id):
   course_mode = CourseMode.DEFAULT_SHOPPINGCART_MODE_SLUG
  else:
   course_mode = None
  if previous_state.enrollment:
   course_mode = previous_state.mode
  enrollment_obj = CourseEnrollment.enroll_by_email(student_email, course_id, course_mode)
  if email_students:
   email_params['message'] = 'enrolled_enroll'
   email_params['email_address'] = student_email
   email_params['full_name'] = previous_state.full_name
   send_mail_to_student(student_email, email_params, language=language)
 else:
  (cea, _) = CourseEnrollmentAllowed.objects.get_or_create(course_id=course_id, email=student_email)
  cea.auto_enroll = auto_enroll
  cea.save()
  if email_students:
   email_params['message'] = 'allowed_enroll'
   email_params['email_address'] = student_email
   send_mail_to_student(student_email, email_params, language=language)
 after_state = EmailEnrollmentState(course_id, student_email)
 return (previous_state, after_state, enrollment_obj)

def enroll_email ( course_id , student_email , auto_enroll = False , email_students = False , email_params = None , language = None ) : previous_state = EmailEnrollmentState ( course_id , student_email ) enrollment_obj = None if previous_state . user : if CourseMode . is_white_label ( course_id ) : course_mode = CourseMode . DEFAULT_SHOPPINGCART_MODE_SLUG else : course_mode = None if previous_state . enrollment : course_mode = previous_state . mode enrollment_obj = CourseEnrollment . enroll_by_email ( student_email , course_id , course_mode ) if email_students : email_params [ 'message' ] = 'enrolled_enroll' email_params [ 'email_address' ] = student_email email_params [ 'full_name' ] = previous_state . full_name send_mail_to_student ( student_email , email_params , language = language ) else : ( cea , _ ) = CourseEnrollmentAllowed . objects . get_or_create ( course_id = course_id , email = student_email ) cea . auto_enroll = auto_enroll cea . save ( ) if email_students : email_params [ 'message' ] = 'allowed_enroll' email_params [ 'email_address' ] = student_email send_mail_to_student ( student_email , email_params , language = language ) after_state = EmailEnrollmentState ( course_id , student_email ) return ( previous_state , after_state , enrollment_obj )
enroll a student by email .