Mail-keeplinkin app code made to run on heroku. https://mail-keeplinkin.herokuapp.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.py 1.6KB

  1. import os
  2. from flask import Flask, render_template, request, redirect, jsonify, abort
  3. import requests
  4. from flask_mail import Mail, Message
  5. app = Flask(__name__)
  6. app.config['MAIL_SERVER']='smtp.zoho.com'
  7. app.config['MAIL_PORT'] = 465
  8. app.config['MAIL_USERNAME'] = os.environ['zoho_username2']
  9. app.config['MAIL_PASSWORD'] = os.environ['zoho_password2']
  10. app.config['MAIL_USE_TLS'] = False
  11. app.config['MAIL_USE_SSL'] = True
  12. @app.route('/')
  13. def main():
  14. return render_template('index.html')
  15. @app.route('/sent/<email>')
  16. def sent(email):
  17. return render_template('sent.html', email=email)
  18. def verify(email):
  19. token="7996de2b-d743-4536-a107-5252fec5c828"
  20. url="https://api.trumail.io/v2/lookups/json?email="+email+"&token="+token
  21. print(url)
  22. data=requests.get(url).json()
  23. return data['deliverable']
  24. @app.route('/send', methods = ['POST'])
  25. def send():
  26. data=request.form
  27. email=data['email'].strip()
  28. subject=data['subject'].strip()
  29. link=data['links'].strip()
  30. arr=link.split('\n')
  31. links="<ol>\n"
  32. for i in range(len(arr)):
  33. links=links + "<li><a href='"+arr[i]+"' target='_blank'>"+arr[i]+"</a></li>"
  34. links=links+"\n<ol>"
  35. if(verify(email)==False):
  36. text="Invalid Email"
  37. return render_template('error.html', text=text, again=True)
  38. mail = Mail(app)
  39. msg = Message(subject, sender = ('Keeplink.in', '[email protected]'), recipients = [email])
  40. msg.html = render_template('email.html', subject=subject, links=links)
  41. test=mail.send(msg)
  42. # print(test)
  43. return redirect("/sent/"+email, code=302)
  44. if __name__ == '__main__':
  45. app.jinja_env.auto_reload = True
  46. app.config['TEMPLATES_AUTO_RELOAD'] = True
  47. # app.run(debug=True, port=4000)
  48. app.run(debug=True)