def send_reset_email(user): token = user.get_reset_token() msg = Message('Password Reset Request', sender='*****@*****.**', recipients=[user.email]) msg.body = f''' To reset the password, visit the following link: {url_for('users.reset_password',token=token, _external=True)} If you didn't make this request, then please ignore the email. ''' mail.send(msg)
def send_reset_email(user): token = user.get_reset_token() msg = Message( "Password Reset Request", sender="*****@*****.**", recipients=[user.email], ) msg.body = f"""To reset your password, visit the following link: {url_for('users.reset_token', token=token, _external=True)} If you did not make this request then simply ignore this email and no changes will be made. """ mail.send(msg)
def send_email(subject, sender, recipients, text_body, html_body): """ 发送电子邮件 :param subject: 标题 :param sender: 发送者 :param recipients: 接收者列表 :param text_body: 纯文本内容 :param html_body: HTML格式内容 :return: """ msg = Message(subject, sender=sender, recipients=recipients) msg.body = text_body msg.html = html_body mail.send(msg) Thread(target=send_async_email, args=(current_app._get_current_object(), msg)).start()
def send_async_email(app, msg): with app.app_context(): mail.send(msg)