def inform_new_student(student):
    path_to_templates = config_get_section_attribute('DIRECTORIES', 'path_to_templates')
    student_email_templates = read_in_templates(path_to_templates + '/student_new_account')
    sender = '"DragonNet Admin" <*****@*****.**>'
    sf = NS(student)
    email = Email(config_get_section_attribute('EMAIL', 'domain'))
    email.define_sender('*****@*****.**', "DragonNet Admin")
    email.use_templates(student_email_templates)
    email.make_subject(sf("New Student in Homeroom {homeroom}, {lastfirst}"))
    homeroom_teacher = student.homeroom_teacher
    if homeroom_teacher:
          email.add_to(homeroom_teacher.email)
    # ssis does not want this feature
    #for guardian_email in student.guardian_emails:
    #      email.add_to(guardian_email)
    # for class_teacher in student.get_teachers_as_list():
    #       email.add_to(class_teacher + '@ssis-suzhou.net')
    # if student.grade in [11, 12]:
    #       email.add_cc('*****@*****.**')
    #       email.add_cc('*****@*****.**')
    # elif student.grade in [6, 7, 8, 9, 10]:
    #       email.add_cc('*****@*****.**')
    email.add_bcc('*****@*****.**')
    email.add_bcc('*****@*****.**')
    email.define_fields(sf)

    email.send()
    def email(self, email: "List or not", cc=None, bcc=None):
        """
        USE THE Email API TO SEND AN EMAIL
        HANDLES IT WHETHER OR NOT LISTS ARE PASSED
        """
        e = Email(self.server)
        e.define_sender(self.sender)
        if isinstance(email, list):
            for item in email:
                e.add_to(item)
        else:
            e.add_to(email)

        if cc:
           if isinstance(cc, list):
               for item in cc:
                   e.add_cc(item)
           else:
               e.add_cc(cc)

        if bcc:
            if isinstance(bcc, list):
                for item in bcc:
                    e.add_bcc(item)
            else:
                e.add_bcc(bcc)

        e.define_subject(self.get_subject())
        e.define_content(self.get_html())

        try:
            e.send()
        except smtplib.SMTPRecipientsRefused:
            self.print_email(email)
def inform_parent_username_changed(parent, password):
    """
    parent is object
    """
    path_to_templates = config_get_section_attribute('DIRECTORIES', 'path_to_templates')
    parent_email_templates = read_in_templates(path_to_templates + '/parent_username_changed')
    email = Email(config_get_section_attribute('EMAIL', 'domain'))
    email.define_sender('*****@*****.**', "DragonNet Admin")
    email.use_templates(parent_email_templates)
    email.make_subject("Notification of updated SSIS DragonNet username")
    email.add_to(parent.email)
    for student in parent.children:
        if student.is_korean:
            email.add_language('kor')
        if student.is_chinese:
            email.add_language('chi')
    email.add_bcc('*****@*****.**')
    email.add_bcc('*****@*****.**')
    email.define_field('username', parent.email)
    email.define_field('salutation', 'Dear SSIS Parent')
    email.define_field('password', password)

    email.send()
def inform_new_parent(parent):
    """
    parent is object
    """
    path_to_templates = config_get_section_attribute('DIRECTORIES', 'path_to_templates')
    parent_email_templates = read_in_templates(path_to_templates + '/parent_new_account')
    email = Email(config_get_section_attribute('EMAIL', 'domain'))
    email.define_sender('*****@*****.**', "DragonNet Admin")
    email.use_templates(parent_email_templates)
    email.make_subject("Your SSIS DragonNet Parent Account")
    for parent_email in parent.emails:
        email.add_to(parent_email)
    for student in parent.children:
        if student.is_korean:
            email.add_language('kor')
        if student.is_chinese:
            email.add_language('chi')
    email.add_bcc('*****@*****.**')
    email.add_bcc('*****@*****.**')
    email.define_field('username', parent.email)
    email.define_field('salutation', 'Dear Parent')

    email.send()