def email_signup(): email = request.form.get('email').lower() if not email: return jsonify(error='no email', status='error') if not validate_email(email, check_mx=True): return jsonify(error='not a valid email', status='error') email_db_obj = Email.query.filter_by(email=email).first() if email_db_obj: # This email is already subscribed. return jsonify(error='already subscribed', status='error') email_db_obj = Email() email_db_obj.email = request.form.get('email') db.session.add(email_db_obj) db.session.commit() session['splash_email_signed_up'] = True # Send a confirmation email to the user mailer = Mailer() mailer.send(BetaSignupConfirmation(), dict(), email) return jsonify(status='ok')
def gegevens(aantal): title = "Afronden" perstukprijs = 5 verzendkosten = 7 aantal = int(aantal) form = GegevensFormulier() if form.validate_on_submit(): order=Order( voornaam=form.voornaam.data, achternaam = form.achternaam.data, email = form.email.data, adres=form.adres.data, postcode=form.postcode.data, plaats=form.postcode.data, aantal=aantal, prijs=perstukprijs*aantal+verzendkosten, ) db.session.add(order) db.session.commit() mailer = Mailer(order.id) error = mailer.send() if error: flash(error) else: flash('Bedankt voor uw bestelling! U ontvangt een e-mail met verdere instructies.') return redirect(url_for('index')) return render_template('gegevens.html', title=title, aantal=aantal, perstukprijs=perstukprijs, verzendkosten=verzendkosten, form=form)
def forgot_password(): if g.user: # Shouldn't be logged in. abort(404) email_sent = False user_to_recover = None if request.method == 'POST' and request.form.get('user_to_recover'): uinput = request.form.get('user_to_recover') # They entered an email. Get the user obj by the email. user_to_recover = User.query.filter_by(email=uinput.lower()).first() if user_to_recover: # Generate a password recovery token for the user. token = PasswordToken.create_for_user(user_to_recover) # Send an email. mailer = Mailer() params = { 'subject': 'Recover your password', 'token': token, 'user_to_recover': user_to_recover }; mailer.send(RecoverPassword(), params, user_to_recover.email) email_sent = True else: # No such user exists. Print an error. flash('No user exists with the given email address exists.') return render_template('users/forgot_password.html', email_sent=email_sent, user_to_recover=user_to_recover)
def drop_a_line(): expected_fields = ["name", "email", "subject", "message"] missing_fields = [] for field in expected_fields: if field not in request.form: missing_fields.append(field) if missing_fields: return jsonify(status="error", missing_fields=missing_fields, error="missing fields"), 400 mailer = Mailer() from_email = request.form["name"] + "<" + request.form["email"] + ">" params = { "name": request.form["name"], "email": request.form["email"], "subject": request.form["subject"], "message": request.form["message"], } mailer.send(DropALine(), params, "*****@*****.**", from_email) return jsonify(status="success")
def signup(): if g.user: return redirect('/') form = SignUpForm() # Check the captcha """ captcha_passed = False if request.method == 'POST': lowered_titles = [x.lower() for x in session.get('captcha_title', [])] if request.form.get('cover','').lower() in lowered_titles: captcha_passed = True else: flash('The text in the image did not match.', 'error') # It's important to only allow one attempt for each session title if 'captcha_title' in session: session.pop('captcha_title') """ valid_form = True # Check for the honey pot. if request.form.get('very_important_field'): # They filled in the honeypot. Most likely, they're a bot. # There can be some weird shit with autocompletes, so just # in case it's an actual user, let's flash a message. flash('Please do not use autocomplete on this form.', 'error') valid_form = False valid_form = valid_form and form.validate_on_submit() # Disabled captacha logic # valid_Form = valid_form and captcha_passed if request.method == 'POST' and valid_form: # Create the user in the database newuser = User() newuser.email = request.form['email'].lower() newuser.first_name = request.form['first_name'] newuser.last_name = request.form['last_name'] newuser.url_keyword = User.generate_url_keyword(newuser.first_name, newuser.last_name) newuser.set_password(request.form['pw']) db.session.add(newuser) # is this user a teacher? if so make a teacher if request.form['is-student'] == "false": db.session.flush() newteacher = Teacher() newteacher.uid = newuser.uid db.session.add(newteacher) db.session.commit() # Send the welcome email. mailer = Mailer() params = { 'subject': 'Welcome to Peernote', 'user': newuser } mailer.send(Welcome(), params, newuser.email) # Log this user in. session['uid'] = newuser.uid current_app.logger.debug('Logging in as uid = %d', session['uid']) return redirect('/') return render_template('users/signup.html', form=form,page_title="Welcome")
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # vim:fileencoding=utf-8 from app.mailer import Mailer from app.parser import Parser from app.template import MailTemplate from app.url_fetcher import URLFetcher fetcher = URLFetcher() fetcher.fetch() if fetcher.content: parser = Parser(fetcher.content) parser.parse() if parser.has_new_content: Mailer.send(MailTemplate(fetcher.url, parser.links))
def email_a_review(): current_app.logger.debug('emailing review for a draft') if 'did' in request.form and 'uid' in request.form and 'email' in request.form: did = request.form['did'] uid = request.form['uid'] email = request.form['email'] draft = Draft.query.filter_by(did=did).first() if not draft or draft.uid != g.user.uid: return jsonify(error="Invalid draft"), 400 if not validate_email(email, check_mx=True): return jsonify(error="Invalid email"), 400 # create review pointing to the draft review = Review() review.did = draft.did review.email = email # really good code to generate a unique url hash for the review unique_hash = False gen_hash = '' while not unique_hash: gen_hash = uuid.uuid4().hex queried_review = Review.query.filter_by(urlhash=gen_hash).first() if not queried_review: unique_hash = True review.urlhash = gen_hash db.session.add(review) # if the draft was not finalized, finalize it and create a new one new_did = None new_version = None new_timestamp = None if not draft.finalized: draft.finalized = True db.session.add(draft) db.session.flush() # make a new draft for the writer new_draft = Draft.next_draft(draft) db.session.add(new_draft) db.session.flush() new_did = new_draft.did new_version = new_draft.version new_timestamp = new_draft.pretty_modified_date() else: db.session.flush() review_url = 'http://' + app.config.get('SERVER_HOST') + '/essays/review/' + review.urlhash # send emailz params = { 'sender': g.user.first_name + ' ' + g.user.last_name, 'review_url': review_url } mailer = Mailer() mailer.send(ReviewADraft(), params, email) # create notification for user receiving review if necessary receiving_user = User.query.filter_by(email=email).first() if receiving_user: notification = Notification() notification.uid = receiving_user.uid notification.from_uid = uid notification.short_template = 'requested a review.' notification.url = review_url notification.long_template = '{{ sender }} wrote an essay and wants you to <a href="' + review_url +'"> review </a> it.' db.session.add(notification) db.session.commit() return jsonify(status='success', new_did=new_did, new_version=new_version, new_timestamp=new_timestamp ) else: return jsonify(error="Bad params"), 400
def load_mailer(): from app.mailer import Mailer app._mailer = Mailer(app) if _config_is_true(app.config.get('SMTP_TEST_ON_START', '')): app._mailer.send_mail('Mail de prueba de web de causas comunes', 'Hola 123') app.logger.info(f'Mail de prueba enviado')
#!/usr/bin/env python # -*- coding: utf-8 -*- # vim:fileencoding=utf-8 from app.mailer import Mailer from app.template import TestMailTemplate Mailer.send(TestMailTemplate(), "Test Email")