This function sends mail using EmailMultiAlternatives and attachs all attachments
    passed as parameters

def send_mail(subject, text_content, from_email, to, html_content=None, attachments=[], cc=[], bcc=[]):
    """
    This function sends mail using EmailMultiAlternatives and attachs all attachments
    passed as parameters
    """
    msg = EmailMultiAlternatives(subject, text_content, from_email, to, cc=cc, bcc=bcc)
    if html_content:
        msg.attach_alternative(html_content, "text/html")
    if attachments:
        for att in attachments:
            if att:

                mimetype = mimetypes.guess_type(att)[0]
                if str(mimetype) in ('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif'):
                    try:
                        with open(att, 'r') as f:
                            email_embed_image(msg, att, f.read())
                    except Exception as e:
                        print(e)
                else:
                    msg.attach_file(att)
    return msg.send()