def send_from_default(recipient, subject, body): sender = current_app.config['MAIL_DEFAULT_SENDER'] msg = Message(subject=subject, html=body, sender=sender, recipients=[recipient]) mail.send(msg)
def send_email(to, subject, template): msg = Message( subject, recipients=[to], html=template, sender=app.config['MAIL_DEFAULT_SENDER'] ) mail.send(msg)
def send_email(title, sender, receivers, html_body, sound_file): msg = Message(title, sender=sender, recipients=receivers) msg.html = html_body # Commented code attaches the results file into the email # Very significant application bottle neck # Try to always send processing results via download link # if sound_file: # msg.attach("results.wav", "audio/wav", sound_file) mail.send(msg)
def send_mail(mail_data): msg = Message( mail_data['subject'], sender=app.config['MAIL_USERNAME'], recipients=mail_data['recipients'] ) msg.body = mail_data['mail_body'] with app.app_context(): mail.send(msg)
def send_email(res, email=None): """ Sends the email with the results to the recipient :param res: The result of the IAT :param email: The email of the recipient :return: Nothing """ msg = Message('Your IAT results', recipients=[email]) msg.body = 'Here are your IAT results: {}'.format(res) mail.send(msg)
def send_to_default(data): subject = '[Prescrisur] ' + bleach.clean(data['subject']) body = bleach.clean(data['body']) sender = (data['sender']['name'], data['sender']['email']) msg = Message(subject=subject, html=body, sender=sender, reply_to=data['sender']['email'], recipients=[current_app.config['DEFAULT_RECIPIENT']]) mail.send(msg)
def send_email(app, msg: Message): r"""Sends an email in the context of the current app. Parameters ---------- app : A Flask app instance A current Flask app. msg : flask_mail.Message Defines a message to be sent. """ with app.app_context(): mail.send(msg)
def send_async_email(app, msg): """ An asynchronous email function to allow the email to be sent by a background thread. :param app: The application instance of the current_app Flask variable :param msg: The Message instance to be sent """ # Flask uses contexts to avoid having to pass arguments across functions. # mail.send() uses config values from the application context with app.app_context(): mail.send(msg)
def send_email(recipients): subject = u"感谢您申领测试机,请填写附件表一并签字,交至市场部肖翔处" msg = Message(subject, sender=(u"肖翔", "*****@*****.**"), recipients=recipients) msg.body = u"感谢您申领测试机,请填写附件表一并签字,交至市场部肖翔处" with app.open_resource(u"regulations.pdf") as fp: msg.attach(filename=u"regulations.pdf", content_type="application/pdf", data=fp.read(), disposition='Content-Disposition') mail.send(msg)
def put(self, session): all = [] amount = 0 all_tickets = request.json["tickets"] for ticket in all_tickets: t = TicketModel.query.filter_by(uuid=ticket).first() if not t: return {"result": False} price: PriceModel = PriceModel.query.filter_by( uuid=t.price_id).first() if not t.paid: amount = amount + price.value all.append(t) if config["MAIL_ENABLED"] and len(all) > 0: msg_title = SettingModel.query.filter_by( key="buy_mail_title").first().value msg_content = SettingModel.query.filter_by( key="buy_mail_content").first().value if msg_title != '' and msg_content != '': cc = SettingModel.query.filter_by(key="mail_cc").first() customer = CustomerModel.query.filter_by( uuid=all[0].customer).first() msg = Message(msg_title, recipients=[customer.email]) if cc and cc.value != '': msg.cc = [cc.value] customer_url = str( config['ENDPOINT']) + 'f/customer/' + customer.uuid msg_content = msg_content.replace( '{{name}}', customer.firstname + ' ' + customer.lastname) msg_content = msg_content.replace( '{{customer}}', '<a href="' + customer_url + '">' + customer_url + '</a>') msg_content = msg_content.replace('{{amount}}', str(int(amount))) msg_content = msg_content.replace('\n', '<br>') msg.html = msg_content mail.send(msg) return {"result": True}
def sendActivationEmail(email): token = UserHandler.getUserToken(email) msg = Message('Email Confirmation Code', sender='*****@*****.**', recipients=[email]) msg.body = f'''To activate your account visit the following link: {url_for('activation_token', token=token, _external=True)} If you did not make this account, then simply ignore this email. ''' mail.send(msg) return jsonify( status='Please check your email to verify it!'), HttpStatus.OK
def send_email(self, to, subject, template): try : msg = Message( subject, recipients=[to], html=template, sender=PRAXYK_API_APP.config['MAIL_DEFAULT_SENDER'] ) mail.send(msg) return True except Exception, e: sys.stderr.write("Exception : " + str(e)) return False
def sendResetPasswordMail(user, token): with app.app_context(): message = Message( "Password Reset Request", sender=app.config['MAIL_DEFAULT_SENDER'], recipients=[user.email] ) message.body = """Hey {}. You have requested to reset your password. Use the below token and send it with the request along with the new password. \nReset Password Token - {}""".format( user.name, token) message.html = render_template("resetPasswordRequest.html", name=user.name, token=token) mail.send(message) logging.info("Reset Password Mail sent to {}".format(user.email))
def twofactorauthenticationmail(user, token, otp): with app.app_context(): digits = "0123456789" message = Message( "Two Factor Authentication", sender=app.config['MAIL_DEFAULT_SENDER'], recipients=[user.email] ) message.body = """Hey {}. Your One Time Password (OTP) is {}. This will expire in the next 10 minutes. Use the below token and send it with the OTP.\nAuthentication Token - {}""".format( user.name, otp, token) message.html = render_template("twoFactorAuthenticationEmail.html", name=user.name, otp=otp, token=token) mail.send(message) logging.info("Sent two factor auth mail to - {}".format(user.email))
def sendAccountVerificationEmail(user, token): with app.app_context(): message = Message( "Account Verification Mail", sender=app.config['MAIL_DEFAULT_SENDER'], recipients=[user.email] ) link = app.config['APP_BASE_URL'] + "/auth/verify?token=" + token message.body = """Hey {}. To verify your account please copy and paste the link below.\n\n{}""".format( user.name, link ) message.html = render_template("accountVerificationEmail.html", name=user.name, link=link) mail.send(message) logging.info("Sent account verification mail to - {}".format(user.email))
def send_mail(subject, html, sender, recipients): try: msg = Message( subject=subject, sender=sender, recipients=recipients, html=html ) mail.send(msg) return {"message": "Send mail successfully", "code": 0} except smtplib.SMTPAuthenticationError: raise InternalServerError(description="SMTP Authentication failed", response=500) except smtplib.SMTPRecipientsRefused: raise InternalServerError(description="Unable to send email to {}".format(recipients), response=500) except Exception as e: raise e
def add_student(): """Adds a student account to the system and sends an activation email. Returns ------- dict Flashes, student data from the form """ flashes = list() try: if not Student.get_by_email(request.form["email"]): student = Student( request.form["email"], request.form["first_name"], request.form["last_name"], ) student.password(request.form["password"]) except KeyError: return error("Not all fields satisfied"), 400 if student.add(): flashes.append("Student added!") logger.info(f"Student {student.email} added") token = current_user.get_activation_token() app = current_app._get_current_object() msg = Message( app.config["MAIL_SUBJECT_PREFIX"] + " " + "Account Activation Link", sender=app.config["MAIL_SENDER"], recipients=[student.email], ) msg.body = f"""Here is your account activation link: { url_for('student.activate_account', token=token, _external=True) } If you did not register for this account, you can ignore this email. If you need any further assistance, please contact [email protected]. """ mail.send(msg) return response(flashes), 200 else: logger.info(f"Error adding Student {student.email}") flashes.append("There was a problem adding this account"), 400 return response(flashes), 400
def reset_password(): """Resets password""" dict_data = request.get_json() email = dict_data.get('email') get_email = Users.query.filter_by(email=email).first() if get_email: password = str(uuid.uuid4())[:8] get_email.password = generate_password_hash(password, method='sha256') db.session.commit() message = Message(subject="Password Reset", sender='*****@*****.**', recipients=[get_email.email], body="Hello" + get_email.username + ",\n Your new password is:" + password) mail.send(message) return jsonify( {'message': 'An email has been sent with your new password!'}), 200 return jsonify({'message': 'Non-existent email. Try signing up'}), 404
def put(self): email = request.json["email"] firstname = request.json["firstname"] lastname = request.json["lastname"] address = request.json["address"] place = request.json["place"] customer: CustomerModel = CustomerModel.create(firstname, lastname, email, address, place) if config["MAIL_ENABLED"]: msg_title = SettingModel.query.filter_by( key="customer_mail_title").first().value msg_content = SettingModel.query.filter_by( key="customer_mail_content").first().value if msg_title != '' and msg_content != '': bcc = SettingModel.query.filter_by(key="mail_bcc").first() msg = Message(msg_title, recipients=[customer.email]) #if bcc and bcc.value != '': # msg.bcc = bcc.value customer_url = str( config['ENDPOINT']) + 'f/customer/' + customer.uuid msg_content = msg_content.replace( '{{name}}', customer.firstname + ' ' + customer.lastname) msg_content = msg_content.replace( '{{customer}}', '<a href="' + customer_url + '">' + customer_url + '</a>') msg_content = msg_content.replace('\n', '<br>') msg.html = msg_content mail.send(msg) return customer.serialize
def put(self): meeting_uuid = request.json["meeting"] customer_uuid = request.json["customer"] bought = [] amount = 0 all_tickets = request.json["buy"] buy_limit = SettingModel.query.filter_by(key="buy_limit").first() if buy_limit and buy_limit.value.isdigit(): if len(all_tickets) + len( TicketModel.query.filter_by( customer=customer_uuid).all()) > int(buy_limit.value): return {"result": False} for ticket in all_tickets: seat_uuid = ticket["seat"] price_uuid = ticket["price"] seat: SeatModel = SeatModel.query.filter_by(uuid=seat_uuid).first() if seat.type == 0: meeting: MeetingModel = MeetingModel.query.filter_by( uuid=meeting_uuid).first() now = int(datetime.now().strftime("%s")) if meeting.start < now and now < meeting.stop: price: PriceModel = PriceModel.query.filter_by( uuid=price_uuid).first() customer: CustomerModel = CustomerModel.query.filter_by( uuid=customer_uuid).first() if TicketModel.query.filter_by( seat_id=seat.uuid, meeting_id=meeting.uuid).first(): return {"result": False} ticket: TicketModel = TicketModel.create( customer, meeting, seat, price) seat.reserved = True db.session.commit() amount = amount + price.value bought.append(ticket) if config["MAIL_ENABLED"] and len(bought) > 0: msg_title = SettingModel.query.filter_by( key="buy_mail_title").first().value msg_content = SettingModel.query.filter_by( key="buy_mail_content").first().value if msg_title != '' and msg_content != '': cc = SettingModel.query.filter_by(key="mail_cc").first() msg = Message(msg_title, recipients=[customer.email]) if cc and cc.value != '': msg.cc = [cc.value] customer_url = str( config['ENDPOINT']) + 'f/customer/' + customer.uuid msg_content = msg_content.replace( '{{name}}', customer.firstname + ' ' + customer.lastname) msg_content = msg_content.replace( '{{customer}}', '<a href="' + customer_url + '">' + customer_url + '</a>') msg_content = msg_content.replace('{{amount}}', str(int(amount))) msg_content = msg_content.replace('\n', '<br>') msg.html = msg_content mail.send(msg) return {"result": True}
def send_message(message): mail.send(message)
def _send_async_email(app, msg): with app.app_context(): mail.send(msg)
def post(self, session): tickets = request.json["tickets"] pay = request.json["pay"] amount = 0 customer = None done = [] for uuid in tickets: ticket: TicketModel = TicketModel.query.filter_by( uuid=uuid).first() ticket.paid = pay db.session.commit() amount = amount + PriceModel.query.filter_by( uuid=ticket.price_id).first().value ticket_customer = customer = CustomerModel.query.filter_by( uuid=ticket.customer).first() if customer and ticket_customer.uuid != customer.uuid: return {"mail": False} else: customer = ticket_customer done.append(ticket) if config["MAIL_ENABLED"] and pay and len(done) > 0: msg_title = SettingModel.query.filter_by( key="ticket_mail_title").first().value msg_content = SettingModel.query.filter_by( key="ticket_mail_content").first().value if msg_title != '' and msg_content != '': cc = SettingModel.query.filter_by(key="mail_cc_paid").first() pdfs = [] for ticket in done: file = download.create_pdf(ticket) pdfs.append( Attachment(filename='ticket_' + ticket.uuid + '.pdf', content_type='application/pdf', data=file)) msg = Message(msg_title, recipients=[customer.email], attachments=pdfs) if cc and cc.value != '': msg.cc = [cc.value] customer_url = str( config['ENDPOINT']) + 'f/customer/' + customer.uuid msg_content = msg_content.replace( '{{name}}', customer.firstname + ' ' + customer.lastname) msg_content = msg_content.replace( '{{customer}}', '<a href="' + customer_url + '">' + customer_url + '</a>') msg_content = msg_content.replace('{{amount}}', str(int(amount))) msg_content = msg_content.replace('\n', '<br>') msg.html = msg_content mail.send(msg) return {"mail": True} return {"mail": False}
def send_async_email(msg, app): with app.app_context(): mail.send(msg)
def send_async_email(api, msg): with api.app_context(): mail.send(msg)
def send_email(to, subject, template): msg = Message(subject, recipients=[to], html=template, sender=app.config['MAIL_DEFAULT_SENDER']) mail.send(msg)