def send_subscription_confirm_mail(user): subject = "Welcome!!" mail_to_be_send = Message(subject=subject, sender=DEFAULT_MAIL_SENDER, recipients=[user['email']]) mail_to_be_send.body = "Congratulaition!" mail.send(mail_to_be_send)
def send_email(subject: str, recipients: List[str], text_body: str, sender: str = None, html_body: str = None) -> None: """Send email via SMTP server""" if sender is None: sender = current_app.config.get("FLASK_MAIL_SENDER") message = Message(subject, sender=sender, recipients=recipients) message.body = text_body message.html = html_body or text_body mail.send(message)
def validate(): name = request.args.get('name', '', type=str) email = request.args.get('email', '', type=str) body = request.args.get('body', '', type=str) if name == '' or email == '' or body == '': return jsonify(err='Please enter all details below') elif not re.match('[\w.]*@[\w]*.[\w]*', email): return jsonify(err='Invalid email address') else: mail.send(name,email,body) flash('Your request has been sent, thank you!') return jsonify(err='NONE')
def validate(): name = request.args.get('name', '', type=str) email = request.args.get('email', '', type=str) body = request.args.get('body', '', type=str) if name == '' or email == '' or body == '': return jsonify(err='Please enter all details below') elif not re.match('[\w.]*@[\w]*.[\w]*', email): return jsonify(err='Invalid email address') else: mail.send(name, email, body) flash('Your request has been sent, thank you!') return jsonify(err='NONE')
def send_register_confirm_mail(user, confirm_url): """ Send the awaiting for confirmation mail to the user. """ subject = "We're waiting for your confirmation!" mail_to_be_send = Message(subject=subject, sender=DEFAULT_MAIL_SENDER, recipients=[user['email']]) signature = signer.sign(str(user['id'])) confirmation_url = confirm_url + "?sign=" + signature mail_to_be_send.body = "Dear %s, click the following url to confirm: %s" % \ (user['email'], confirmation_url) mail.send(mail_to_be_send)
def auth_register(): if not request.is_json: return jsonify({"msg": "Missing JSON in request"}), 400 password = request.json.get('password', None) mail = request.json.get('mail', None) if not password: return jsonify({"msg": "Missing password parameter"}), 400 if not mail: return jsonify({"msg": "Missing mail parameter"}), 400 code = fn_user_add(mail, password) if code == 201: subject = '[🐒&🐖] Bienvenue chez le Singouins !' token = generate_confirmation_token(mail) url = API_URL + '/auth/confirm/' + token body = open("/code/data/registered.html", "r").read() if send( mail, subject, body.format(urllogo='[INSERT LOGO HERE]', urlconfirm=url, urldiscord=DISCORD_URL)): return jsonify({"msg": "User successfully added | mail OK"}), code else: return jsonify({"msg": "User successfully added | mail KO"}), 206 elif code == 409: return jsonify({"msg": "User or Email already exists"}), code else: return jsonify({"msg": "Oops!"}), 422
def send_reset_password_mail(email, reset_url): """ Send a reset mail to user, allow the user to reset password. """ subject = "Reset Password" mail_to_be_send = Message(subject=subject, sender=DEFAULT_MAIL_SENDER, recipients=[email]) reset_code = uuid.uuid4() reset_url = reset_url + "?code=" + str(reset_code) mail_to_be_send.body = "Dear %s, click the following url to reset your password:%s" % \ (email, reset_url) mysql.execute( """insert into reset (email, reset_code) values(%s, %s) """, email, reset_code) mysql.commit() mail.send(mail_to_be_send)
def auth_forgotpassword(): if not request.is_json: return jsonify({"msg": "Missing JSON in request"}), 400 mail = request.json.get('mail', None) (code, password) = fn_forgot_password(mail) if code == 200: subject = '[🐒&🐖] Mot de passe oublié' token = generate_confirmation_token(mail) url = API_URL + '/auth/confirm/' + token body = open("/code/data/forgot_password.html", "r").read() if send( mail, subject, body.format(urllogo='[INSERT LOGO HERE]', password=password, urldiscord=DISCORD_URL)): return jsonify({"msg": "Password successfully replaced | mail OK"}), code else: return jsonify({"msg": "Password successfully replaced | mail KO"}), 206 else: return jsonify({"msg": "Oops!"}), 422
def send_async_email(app, msg): with app.app_context(): mail.send(msg)