daily pastebin goal
6%
SHARE
TWEET

Untitled

a guest Sep 26th, 2016 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from flask import Flask, render_template, request, redirect, url_for
  2. from flask_mail import Mail, Message
  3. import random
  4. import string
  5.  
  6.  
  7. def random_generator(size=6, chars=string.ascii_letters + string.digits):
  8.     return ''.join(random.choice(chars) for x in range(size))
  9.  
  10.  
  11. subscribers_d = {'anshul.bansal5@yahoo.com': 'Anshul Bansal', 'anshul.bansal3@yahoo.com': 'Bansal', 'anshul.bansal@yahoo.com': 'Anshul',}
  12.  
  13. app = Flask(__name__)
  14. mail = Mail(app)
  15.  
  16. app.config.update(
  17.     MAIL_SERVER='smtp.gmail.com',
  18.     MAIL_PORT=465,
  19.     MAIL_USE_TLS = False,
  20.     MAIL_USE_SSL=True,
  21.     MAIL_USERNAME='anshul.bansal950@gmail.com',
  22.     MAIL_PASSWORD="It's Secret"
  23. )
  24.  
  25.  
  26. @app.route('/')
  27. def index():
  28.     return render_template("index.html")
  29.  
  30.  
  31. @app.route('/submit', methods=['POST'])
  32. def submit():
  33.     if request.method == "POST":
  34.         v_name = request.form['vname']
  35.         v_email = request.form['vemail']
  36.         return send_mail(v_name, v_email)
  37.     else:
  38.         return redirect(url_for("/"))
  39.  
  40. random_link_sent = random_generator(20)
  41.  
  42.  
  43. @app.route("/")
  44. def send_mail(v_name, v_email):
  45.     if v_email in subscribers_d:
  46.         return "Oh! It seems that you have already registered."
  47.     else:
  48.         msg = Message('Confirm Subscription', sender=['anshul.bansal950@gmail.com'], recipients=[v_email])
  49.         msg.html = "<h3>Confirm Subscription</h3>"
  50.            "<p>Hi! </p>" + v_name + "<p> , Please click on below link to subscribe</p>"
  51.             "Link: " + ' www.anshulbansal.esy.es/' + random_link_sent
  52.         mail.send(msg)
  53.         return 'Check Your Inbox For Confirmation Email'
  54.  
  55.  
  56. @app.route("/<random_link_sent>")
  57. def confirm(random_link_sent):
  58.     return "You have registered on " + random_link_sent
  59.     subscribers_d[v_email] = v_name
  60.  
  61.  
  62. if __name__ == "__main__":
  63.     app.run(debug=True)
  64.    
  65. MAIL_SERVER = 'smtp.googlemail.com'
  66. MAIL_PORT = 587
  67. MAIL_USE_TLS = True
  68. MAIL_USERNAME='anshul.bansal950@gmail.com',
  69. MAIL_PASSWORD="It's Secret"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top