def contact(): """Send an email to the ADMINS.""" current_app.logger.info('Entering meta.views.contact()...') form = ContactUsForm() if form.validate_on_submit(): subject = '[%s] Message from %s: %s' % (current_app.config['APP_NAME'], form.full_name.data, form.subject.data) date = get_current_time() css = get_resource_as_string('static/css/email.css') html = render_template('meta/emails/contact.html', css=css, email_recipient=form.email.data, full_name=form.full_name.data, date=date, title=subject, message=form.message.data) p = Premailer(html) result_html = p.transform() message = Message(subject=subject, html=result_html, reply_to=form.email.data, recipients=current_app.config['ADMINS']) mail.send(message) flash(_("Thanks for your message. We'll get back to you shortly."), 'success') current_app.logger.debug('Returning success.') response = jsonify(status='success') response.status_code = 200 return response
def send_invite(self, form, url): recipients = form['email'].split(";") body="Hello !\r\n\r\nYou are invited to partipate to this videoconferencing, please click on this link (only working with the latest chrome browser)\r\n%s" % url msg = Message(subject="Video conf invitation", body=body, sender="*****@*****.**", recipients=recipients) mail.send(msg)
def send_email(subject, sender, recipients, html): msg = Message( subject=subject, sender= sender, recipients= [recipients] ) msg.html = html mail.send(msg)
def send_registration_email(user, token): msg = Message( 'User Registration', sender='*****@*****.**', recipients=[user.email] ) msg.body = render_template( 'mail/registration.mail', user=user, token=token ) mail.send(msg)
def post(): """Create a session.""" current_app.logger.info('Entering session.views.post()...') form = LoginForm() if form.validate_on_submit(): user, authenticated = User.authenticate(form.email.data, form.password.data) if user and authenticated: if login_user(user, remember='y'): response = jsonify(status='success', data=user.session_as_dict()) response.status_code = 200 current_app.logger.debug('Returning success; response.data=[%s]' % response.data) return response else: # User reactivation request. user.activation_key = str(uuid4()) db.session.add(user) db.session.commit() # Send reactivation confirmation email. css = get_resource_as_string('static/css/email.css') reactivate_url = '%s/#accounts/reactivate/%s/%s/' % (current_app.config['DOMAIN'], quote(user.email), user.activation_key) html = render_template('user/emails/reactivate_confirm.html', css=css, username=user.username, email_recipient=user.email, reactivate_url=reactivate_url) current_app.logger.debug('reactivate_url=[%s]' % reactivate_url) p = Premailer(html) result_html = p.transform() message = Message(subject='%s Account Reactivation' % current_app.config['APP_NAME'], html=result_html, recipients=[user.email]) try: mail.send(message) except SMTPDataError as e: current_app.logger.debug('Returning fail = [%s].' % e) response = jsonify(status='fail', data={'email': "Couldn't send email to %s." % form.email.data}) response.status_code = 200 return response # Return response response = jsonify(status='success', data=user.session_as_dict()) response.status_code = 200 current_app.logger.debug('Returning success') return response else: response = jsonify(status='fail', data={'email': _('Wrong email/password.')}) response.status_code = 200 current_app.logger.debug('Returning success; response.data=[%s]' % response.data) return response else: current_app.logger.debug('Returning fail; data = [%s].' % form.errors) return jsonify(status='fail', data=form.errors)
def send_registration_email(uid, token): """Sends a registratiion email to the given uid.""" user = User.query.filter_by(id=uid).first() msg = Message( 'User Registration', sender='*****@*****.**', recipients=[user.email] ) msg.body = render_template( 'mail/registration.mail', user=user, token=token ) mail.send(msg)
def forgot_password(): form = ForgotPasswordForm() if form.validate_on_submit(): email = form.email.data user = User.query.filter_by(email=email).first() if user: token = user.get_token() msg = Message('PasswordReset[MedQa]', sender = '*****@*****.**', recipients=[user.email]) msg.body = "You're receiving this email because you requested a password reset for your user account at Medqa.in\n\n Please go to the following page and choose a new password:\n http://0.0.0.0:5000/reset_password?token=" + token+ "\n\nThanks!\nTeam Medqa" mail.send(msg) return "sent" else: error = "Email Address Not Registered!" print error return render_template('user/forgot_password.html',form=form) return render_template('user/forgot_password.html',form=form)
def password_reset(): """Request a password reset for a user.""" form = RecoverPasswordForm() # TODO: Refactor this logic so the if block is not nested if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data).first() if user: user.activation_key = str(uuid4()) db.session.add(user) db.session.commit() # Send reset password email. css = get_resource_as_string('static/css/email.css') change_password_url = '%s/#accounts/password/reset/confirm/%s/%s/' % (current_app.config['DOMAIN'], quote(user.email), quote(user.activation_key)) html = render_template('user/emails/reset_password.html', css=css, username=user.username, email_recipient=user.email, change_password_url=change_password_url) current_app.logger.debug('change_password_url=[%s]' % change_password_url) p = Premailer(html) result_html = p.transform() message = Message(subject='Recover your password', html=result_html, recipients=[user.email]) try: mail.send(message) except SMTPDataError as e: current_app.logger.debug('Returning fail = [%s].' % e) response = jsonify(status='fail', data={'email': "Couldn't send email to %s." % form.email.data}) response.status_code = 200 return response current_app.logger.debug('Returning success.') response = jsonify(status='success') response.status_code = 200 return response else: current_app.logger.debug('Returning fail = [Sorry, no user found for that email address.].') response = jsonify(status='fail', data={'email': 'Sorry, no user found for that email address.'}) response.status_code = 200 return response else: current_app.logger.debug('Returning fail = [%s].' % form.errors) response = jsonify(status='fail', data=form.errors) response.status_code = 200 return response
def delete(id): """Delete a user.""" current_app.logger.info('Entering users.views.delete()...') # TODO: Verify that id === current_user.id user = User.query.get(id) form = DeactivateAccountForm() if form.validate(): user.status_id = INACTIVE db.session.add(user) db.session.commit() # Send deactivation receipt email css = get_resource_as_string('static/css/email.css') reactivate_request_url = '%s/#sessions/login/' % current_app.config['DOMAIN'] current_app.logger.debug('reactivate_request_url=[%s]' % reactivate_request_url) html = render_template('user/emails/deactivate_receipt.html', css=css, username=user.username, email_recipient=user.email, reactivate_request_url=reactivate_request_url) p = Premailer(html) result_html = p.transform() message = Message(subject='Your %s account is now deactivated' % current_app.config['APP_NAME'], html=result_html, recipients=[user.email]) try: mail.send(message) except SMTPDataError as e: current_app.logger.error('Returning fail = [%s].' % e) response = jsonify(status='fail', data={'email': "Couldn't send email to %s." % form.email.data}) response.status_code = 200 return response # Return response response = jsonify(status='success') response.status_code = 200 return response else: response = jsonify(status='fail', data=form.errors) current_app.logger.debug('form errors = [%s]' % form.errors) response.status_code = 200 return response
def send_async_service_email(app, subject, recipients, html): with app.app_context(): msg = Message(subject, recipients, html=html) mail.send(msg)
def send_async_email(m): mail.send(m)
def send_async_email(app, subject, recipients, body): with app.app_context(): msg = Message(subject, recipients, body) mail.send(msg)
def send_async_email(app, msg): with app.app_context(): mail.send(msg)
def send_async_email(app, msg): """Helper function to send asynchronous email""" # applcation context needs to be manually pushed since it is # thread local with app.app_context(): mail.send(msg)
def async_send_mail(app, msg): with app.app_context(): mail.send(msg)
def async_send_mail(app, msg): # 邮件发送需要诚信上下文,否则发送不了 # 由于是新的线程,没有上下文,需要手动创建 with app.app_context(): mail.send(msg)
def async_send_mail(app, msg): # 需要程序上下文.否则发送不了 # 新的线程,没有上下文,需要手动创建 with app.app_context(): mail.send(msg)
def sendMail(content): with app.app_context(): msg = Message(content, recipients=['*****@*****.**'], body=content) mail.send(msg)
def send_async_mail(app, msg): with app.app_context(): try: mail.send(msg) except Exception as e: raise e
def post(): """Create a session.""" current_app.logger.info('Entering session.views.post()...') form = LoginForm() if form.validate_on_submit(): user, authenticated = User.authenticate(form.email.data, form.password.data) if user and authenticated: if login_user(user, remember='y'): response = jsonify(status='success', data=user.session_as_dict()) response.status_code = 200 current_app.logger.debug( 'Returning success; response.data=[%s]' % response.data) return response else: # User reactivation request. user.activation_key = str(uuid4()) db.session.add(user) db.session.commit() # Send reactivation confirmation email. css = get_resource_as_string('static/css/email.css') reactivate_url = '%s/#accounts/reactivate/%s/%s/' % ( current_app.config['DOMAIN'], quote( user.email), user.activation_key) html = render_template('user/emails/reactivate_confirm.html', css=css, username=user.username, email_recipient=user.email, reactivate_url=reactivate_url) current_app.logger.debug('reactivate_url=[%s]' % reactivate_url) p = Premailer(html) result_html = p.transform() message = Message(subject='%s Account Reactivation' % current_app.config['APP_NAME'], html=result_html, recipients=[user.email]) try: mail.send(message) except SMTPDataError as e: current_app.logger.debug('Returning fail = [%s].' % e) response = jsonify(status='fail', data={ 'email': "Couldn't send email to %s." % form.email.data }) response.status_code = 200 return response # Return response response = jsonify(status='success', data=user.session_as_dict()) response.status_code = 200 current_app.logger.debug('Returning success') return response else: response = jsonify(status='fail', data={'email': _('Wrong email/password.')}) response.status_code = 200 current_app.logger.debug('Returning success; response.data=[%s]' % response.data) return response else: current_app.logger.debug('Returning fail; data = [%s].' % form.errors) return jsonify(status='fail', data=form.errors)
def async_send_mail(app, msg): # 发送邮件需要程序上下文 with app.app_context(): mail.send(msg)
def _send_async(app, msg): with app.app_context(): mail.send(msg)
def async_send_mail(app, msg): # 获取当前程序的上下文 with app.app_context(): mail.send(message=msg)
def async_send_mail(app, msg): # 发送邮件必须在程序上下文中,新的线程中需要手动创建 with app.app_context(): mail.send(msg)
def async_send_mail(app, msg): # 邮件发送需要程序上下文,新的线程没有,需要手动创建 with app.app_context(): mail.send(msg)
def send_async_email(msg): mail.send(msg)
def _send_async_mail(app, message): with app.app_context(): mail.send(message)
def async_send_mail(app, msg): # 发送邮件需要程序上下文, 否则无法发送 # 在新的线程中没有上下文,需要手动创建 with app.app_context(): mail.send(msg)
def send_async_email(email_data): msg = Message(email_data['subject'], recipients=email_data['to'], body=email_data['body']) mail.send(msg)
def send_async_mail(app, msg): # 邮件发送必须在线程上下文中,因此需要自己创建上下文 with app.app_context(): mail.send(msg)
def async_send(app, msg): # 通过with 管理线程 with app.app_context(): mail.send(msg)
def async_send_mail(app, msg): # 必须在程序上下文中才能发送邮件,新建的线程没有,因此需要手动创建 with app.app_context(): # 发送邮件 mail.send(msg)
def async_send_mail(app, msg): # 邮件发送需要在程序上下文中进行,新的线程中没有上下文,需要手动创建 with app.app_context(): # 创建上下文 mail.send(msg)
def send_email(subject, sender, recipients, text_body, html_body): msg = Message(subject, sender=sender, recipients=recipients) msg.body = text_body msg.html = html_body mail.send(msg)
def async_send_mail(app, msg): # 邮件发送需要在程序上下文中进行, # 新的线程中没有上下文,需要手动创建 with app.app_context(): mail.send(msg) print('成功发送')
def send_welcome_email(name: str, email: str): msg_body = f"<h1>{name} Welcome to the Flask-skeleton family</h1>" msg = Message(subject="Welcome", recipients=[email], html=msg_body) msg.sender = "*****@*****.**" mail.send(msg)
def retry_send(msg): # print('Sending ...') mail.send(msg)