'Enroll a user in a course given their email. This saves immediately.
Note that  enrolling by email is generally done in big batches and the
error rate is high. For that reason, we supress User lookup errors by
default.
Returns a CoursewareEnrollment object. If the User does not exist and
`ignore_errors` is set to `True`, it will return None.
`email` Email address of the User to add to enroll in the course.
`course_id` is our usual course_id string (e.g. "edX/Test101/2013_Fall)
`mode` is a string specifying what kind of enrollment this is. The
default is the default course mode, \'audit\'. Other options
include \'professional\', \'verified\', \'honor\',
\'no-id-professional\' and \'credit\'.
See CourseMode in common/djangoapps/course_modes/models.py.
`ignore_errors` is a boolean indicating whether we should suppress
`User.DoesNotExist` errors (returning None) or let it
bubble up.
It is expected that this method is called from a method which has already
verified the user authentication and access.'

@classmethod
def enroll_by_email(cls, email, course_id, mode=None, ignore_errors=True):

    try:
        user = User.objects.get(email=email)
        return cls.enroll(user, course_id, mode)
    except User.DoesNotExist:
        err_msg = u'Tried    to    enroll    email    {}    into    course    {},    but    user    not    found'
        log.error(err_msg.format(email, course_id))
        if ignore_errors:
            return None
        raise
