from flask_mail import Message
from app import app, mail


def generate_email(code, email):
    with open("mail/" + email, 'r') as file:
        email = file.read()
    return email.replace("[CODE]", code)


def send_mail(address, code, email):
    msg = Message(
        subject="matchinit verification code",
        recipients=[address],
        html=generate_email(code, email),
        sender=app.config['MAIL_DEFAULT_SENDER']
    )
    mail.send(msg)
