'Create an instance of CourseEmail.'

@classmethod
def create(cls, course_id, sender, targets, subject, html_message, text_message=None, template_name=None, from_addr=None):

    if (text_message is None):
        text_message = html_to_text(html_message)
    new_targets = []
    for target in targets:
        target_split = target.split(':', 1)
        if (target_split[0] not in EMAIL_TARGETS):
            fmt = 'Course    email    being    sent    to    unrecognized    target:    "{target}"    for    "{course}",    subject    "{subject}"'
            msg = fmt.format(target=target, course=course_id, subject=subject)
            raise ValueError(msg)
        elif (target_split[0] == SEND_TO_COHORT):
            cohort = CohortTarget.ensure_valid_cohort(target_split[1], course_id)
            (new_target, _) = CohortTarget.objects.get_or_create(target_type=target_split[0], cohort=cohort)
        elif (target_split[0] == SEND_TO_TRACK):
            CourseModeTarget.ensure_valid_mode(target_split[1], course_id)
            mode = CourseMode.objects.filter(course_id=course_id, mode_slug=target_split[1])[0]
            (new_target, _) = CourseModeTarget.objects.get_or_create(target_type=target_split[0], track=mode)
        else:
            (new_target, _) = Target.objects.get_or_create(target_type=target_split[0])
        new_targets.append(new_target)
    course_email = cls(course_id=course_id, sender=sender, subject=subject, html_message=html_message, text_message=text_message, template_name=template_name, from_addr=from_addr)
    course_email.save()
    course_email.targets.add(*new_targets)
    course_email.save()
    return course_email
