def resend_email(): error = "" form = ForgotForm() if form.validate_on_submit(): email = form.email.data user = alumni.query.filter_by(info_email=email).first() if user is not None: token = s.dumps(email, salt='email-confirm') msg = Message('Confirm Email', sender='*****@*****.**', recipients=[email]) link = url_for('confirm_email', token=token, _external=True) msg.body = 'Click here to verify email {}'.format(link) mail.send(msg) return redirect(url_for('gotoemail')) else: error = "Invalid credentials" html = render_template('pages/login/resend_email.html', form=form, errors=[error]) # MAKE THIS return make_response(html)
def post(self): args = self.post_parser.parse_args() user = User.where('email', args['email']).get().first() if (user is None): response = jsonify({"message": "User not found"}) response.status_code = 404 return response # TODO: Use User's static methods token = self.encode_token(user) user_token = user.resettoken().order_by('created_at', 'desc').first() if (user_token is not None): user_token.active = False user_token.save() user_token = user.resettoken().create(token=token, active=True) msg = Message('Smart Switch password reset', recipients=[args['email']]) msg.body = "%s?resettoken=%s" % (app.config['web-client'], user_token.token) mail.send(msg) response = jsonify({"message": "Password reset token", "token": token}) response.status_code = 200 return response
def send_email_edit_password(): dict=json.loads(request.get_data(as_text=True)) email = dict.get('email','') type = dict.get('type',0) if not type or not email: return jsonify({'status':'fail'}) msg.recipients=[] msg.recipients.append(email) code = '' for i in range(0,4): code += str(random.randint(0,9)) if type == 1: key = "email_type_1" msg.body = '您的账户正在试图修改密码,如非本人操作请忽略,您的验证码为'+code elif type == 2: key = "email_type_2" msg.body = '您的账户正在试图更换绑定的邮箱,如非本人操作请忽略,您的验证码为' + code elif type == 3: key = "email_type_3" msg.body = '有账户正在试图更换绑定的邮箱账号至此邮箱,如非本人操作请忽略,您的验证码为' + code else: key = "email_type_4" msg.body = '您的验证码为' + code mail.send(msg) rd.hset(key,email,code) thread_1 = threading.Thread(target=del_verify_code,args=(key,email)) thread_1.start() return jsonify({'status':'success'})
def signup(): error = "" form = RegisterForm() if form.validate_on_submit(): email = form.email.data hashed_password = generate_password_hash(form.password.data, method='sha256') existing_user = alumni.query.filter_by(info_email=email).first() if existing_user is None: token = s.dumps(email, salt='email-confirm') msg = Message('Confirm Email', sender='*****@*****.**', recipients=[email]) link = url_for('confirm_email', token=token, _external=True) msg.body = 'Confirmation link is {}'.format(link) mail.send(msg) user = alumni(info_email=email, password=hashed_password) upsert_user(user, side='alum') return redirect(url_for('gotoemail')) error = 'Invalid' html = render_template('pages/login/signup.html', form=form, errors=[error]) return make_response(html)
def send_mail(recipients: list, title, content_txt: str = None, content_html=None): from config import app if app.config['SEND_MAIL']: print('DEBUG状态,邮件被禁止发送了 \r\n \t%s \r\n \t%s \r\n \t%s' % (recipients, title, content_txt if content_html is None else content_html)) return from flask_mail import Message from config import mail msg = Message(title, sender=('oneself - service', app.config['MAIL_USERNAME']), recipients=recipients) msg.body = content_txt msg.html = content_html try: mail.send(msg) except Exception: try: with app.app_context(): mail.send(msg) except Exception as e: import traceback i('邮件发送失败%s' % traceback.format_exc())
def mailid(): if request.form.get('input_email') != '': # tablelist = visit.query.filter_by(email=request.form.get('input_email')).first() visitquery = db.engine.execute("SELECT * FROM session WHERE email = '" + request.form.get('input_email') + "'") # testing if visitquery.rowcount != 0: # Has user record for record in visitquery: retrieve_mail = Message( 'Your report ID from Traumatic Brain Injury Decision Aid Tool', sender='*****@*****.**', recipients=[request.form.get('input_email')]) retrieve_mail.html = render_template("email/forget_mail.html", record=record) mail.send(retrieve_mail) alertmsg = 'The Report ID has been sent to your E-mail.' print("mail has been sent") return render_template("content/home.html", alertmsg=alertmsg) else: alertmsg = "No matched record" return render_template("content/home.html", alertmsg=alertmsg) else: alertmsg = "You have to input your E-mail address" return render_template("content/home.html", alertmsg=alertmsg)
def sendmail(): msg = Message("Hello", sender="*****@*****.**", recipients=["*****@*****.**"]) msg.body = render_template('mail.html', name='ben') msg.html = render_template('mail.html', name='ben') mail.send(msg) return 'ok'
def send_reset_mailSuccess(user): msg = Message('Password Reset Request', sender='*****@*****.**', recipients=[user.email]) msg.body = f''' Your password for {user.username} reset succefully. Enjoy your day. ''' mail.send(msg)
def send_reset_mail(user): token = user.get_reset_token() msg = Message('Password Reset Request', sender='*****@*****.**', recipients=[user.email]) msg.html = render_template("sentmaillink.html", token=token, user=user.username) mail.send(msg) return token
def post(self): email = request.json['email'] msg = Message("Send Mail Tutorial!", sender="*****@*****.**", recipients=[email]) msg.body = "Yo!\nHave you heard the good word of Python???" mail.send(msg) return "email send"
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('reset_request', _external=True)}/{token} if you did not make this email request simply ignore this email. """ mail.send(msg)
def sendcontact(): msg = Message( 'User Feedback: ' + request.form.get('subject'), sender='*****@*****.**', recipients=['*****@*****.**']) msg.html = "<p> Name: " + request.form.get('name') + "</p><p> Email: " + request.form.get( 'email') + "</p><p>" + request.form.get('message') mail.send(msg) # flash("Your feedback has been sent to us, we'll reply you as soon as possible. Thank you!") # return ('', 204) return render_template("content/home.html", feedback="Your feedback has been sent to us, we'll reply you as soon as possible. Thank you!")
def send_email(): dict = json.loads(request.get_data(as_text=True)) email = dict.get('register_email', '') msg.recipients = [] msg.recipients.append(email) code = '' for i in range(0, 4): code += str(random.randint(0, 9)) msg.body = '您的验证码为' + code mail.send(msg) rd.set(email, code) return jsonify({'status': 'success'})
def feedback(): form = SendFeedback() if form.validate_on_submit(): msg = Message(subject=f"Squirrel Feedback from {current_user.username}", body=f"Feedback from: {current_user.username } at {current_user.email}\n{form.message.data}", sender=app.config.get("MAIL_USERNAME"), recipients=[app.config.get("MAIL_USERNAME")]) mail.send(msg) flash("Thank you for your feedback!", "success") return redirect(url_for('listing')) return render_template('pages/feedback.html', form=form, title="Feedback")
def send_mail(email, subject, body): try: msg = Message( subject=subject, sender='*****@*****.**', recipients=[email], ) msg.body = body mail.send(msg) except Exception: raise RuntimeError('Something went wrong while sending email message.')
def sendmail(): if session['email'] != '': # Email: Subject, sender, recipient msg = Message('Your report from Traumatic Brain Injury Decision Aid Tool -- Report ID: ' + str(session['id']), sender='*****@*****.**', recipients=[session['email']]) # Email: Body msg.html = render_template('include/textreport.html') try: mail.send(msg) except Exception: session['alertmsg'] = "E-mail sent unsuccessfully, Please try again." return render_template("summary.html") session['alertmsg'] = 'The report has been sent.' return render_template("summary.html")
def recuperar_pass(usuario_id): if (usuario_id != "" and usuario_id.isdigit()): usuario_email = Usuario.get(Usuario.id == usuario_id).email nuevo_pass = str(time.time())[0:5] usuario_recuperado = Usuario.update(password=md5(nuevo_pass).hexdigest())\ .where(Usuario.id == usuario_id) usuario_recuperado.execute() confirmacion = Message("Recuperar Contraseña", sender=("Sistema", "*****@*****.**"), recipients=[usuario_email]) confirmacion.body = "Su nueva contraseña es: %s" % nuevo_pass mail.send(confirmacion) return redirect(url_for("home")) else: abort(406)
def notify(selective=False, members=None): username, id = verify_admin() msg = '' match_list = members if selective else matches.query.filter_by( group_id=id).all() if not match_list: errorMsg = 'There are no members to notify' html = render_template('pages/admin/modify-matches.html', errorMsg=errorMsg, username=username, id=id, user_type='admin') return make_response(html) student_emails = [] alum_emails = [] for match in match_list: student = students_table.query.filter_by( studentid=match.studentid).first().info_email student_emails.append(student) alum_emails.append(match.info_email) student_link = 'https://tigerpair.herokuapp.com/student/dashboard' student_msg = Message('You\'ve been Matched!', sender='*****@*****.**', bcc=student_emails) student_msg.body = f'You have been assigned a match! Visit the link below to view your match and reach out to them as soon as possible to confirm your pairing.\n\n{student_link}\n\nIf you do not reach out within 10 days your match will be removed and reassigned to another alum.\n\nBest,\nThe TigerPair Team' mail.send(student_msg) alum_link = 'https://tigerpair.herokuapp.com/alum/dashboard' alum_msg = Message('You\'ve been Matched!', sender='*****@*****.**', bcc=alum_emails) alum_msg.body = f'You have been assigned a match! Visit the link below to view your match and look out for an email from them in coming days.\n\n{alum_link}\n\nIf they do not reach out let admin know to be reassigned. Thank you for participating in this program.\n\nBest,\nThe TigerPair Team' mail.send(alum_msg) successMsg = 'Email notifications successfully sent!' html = render_template('pages/admin/modify-matches.html', successMsg=successMsg, username=username, id=id, user_type='admin') return make_response(html)
def flask_plain_email(recipient, subject, content, cc, bcc): with app.app_context(): #Instantiate a new message msg = Message(recipients=[recipient, cc, bcc], subject=subject, body=content) try: res = mail.send(msg) response = { 'status': 'success', 'data': { 'message': 'Mail sent successfully' } } # return print(res) return make_response(jsonify(response), 201) except Exception: response = { 'status': 'error', 'data': { 'message': 'Error: Mail was not sent.' } } return make_response(jsonify(response), 500)
def sendMail(): data = request.get_json(force=True) msg = Message(data[2], sender='*****@*****.**', recipients=['*****@*****.**']) msg.body = """From: %s; \n\nEmail: %s; \n\n%s""" % (data[0], data[1], data[3]) mail.send(msg)
def send_mail(subject, sender, recipients, text_body, html_body, cc= None, bcc=None): message = Message(subject=subject, sender=sender, recipients=recipients, cc=cc, bcc=bcc) message.body = text_body message.html = html_body mail.send(message)
def user_dashboard(side): username, user = verify_user(side) route_new_user(user, side) form2 = ChangeGroupForm() is_alum = side == 'alum' errorMsg = '' successMsg = '' match_user = None if is_alum: match = matches.query.filter_by(info_email=username).first() if match is not None: match_user = students.query.filter_by( studentid=match.studentid).first() else: match = matches.query.filter_by(studentid=username).first() if match is not None: match_user = alumni.query.filter_by( info_email=match.info_email).first() if request.form.get("action") == "Confirm": if match is not None: match.contacted = True db.session.commit() contacted = False if match is None else match.contacted html = render_template('pages/user/dashboard.html', match=match_user, username=username, user=user, side=side, contacted=contacted, user_type=side, form2=form2) if request.form.get("message") is not None: try: try: time = user.last_message last_time = datetime.strptime( str(time).split('.')[0], '%Y-%m-%d %H:%M:%S') except: pass if (datetime.utcnow() - last_time).seconds / 3600 < 1: errorMsg = 'You may not send more than one message per hour.' else: where_clause = f"info_email='{user.info_email}'" if is_alum else f"studentid='{user.studentid}'" db.engine.execute( f"UPDATE {'alumni' if is_alum else 'students'} SET last_message=now() WHERE {where_clause}" ) db.session.commit() group_id = user.group_id admin = admins.query.filter_by(id=group_id).first() email = admin.username + "@princeton.edu" message = request.form.get("message") msg = Message(f'TigerPair {side.capitalize()} Message', sender='*****@*****.**', recipients=[email]) msg.body = message + \ f"\n --- \nThis message was sent to you from the {side}: " + username mail.send(msg) successMsg = 'Message successfully sent!' except Exception as e: print(e) html = render_template('pages/user/dashboard.html', match=match_user, username=username, user=user, side=side, contacted=contacted, successMsg=successMsg, errorMsg=errorMsg, user_type=side, form2=form2) return make_response(html)
def send_email(to, subject, template): message = Message(subject, recipients=[to], html=template, sender=app.config['MAIL_DEFAULT_SENDER']) mail.send(message)
def send_async_email(message): with app.app_context(): mail.send(message)