-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.py
73 lines (59 loc) · 2.3 KB
/
contact.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Serves a simple contact form.
Takes email username and password as space separated arguments.
"""
import sys
import json
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from flask import Flask, Response, jsonify, render_template, url_for
app = Flask(__name__)
@app.route('/')
def media():
url_for('static', filename='main.css')
url_for('static', filename='background.png')
url_for('static', filename='OptionsCity-Logo-Black.png')
return
@app.route('/contact/')
def index():
return render_template('index.html', message="Learn more about us by leaving your email here.")
@app.route('/send_email/<email_address>')
def send_email(email_address):
# pass username and password as options to server
EMAIL_HOST_USER = sys.argv[1]
EMAIL_HOST_PASSWORD = sys.argv[2]
# create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Thanks for your interest in OptionsCity!"
msg['From'] = EMAIL_HOST_USER
msg['To'] = email_address
# message body
html = '''<html><body><table style="text-align: left;">
<tr>
<td>To quickly start hacking, grab an <a href="http://devservices.optionshop.com/mhacks">API Access Token URL</a>.</td>
</tr>
<tr>
<td>To learn more about our API, check out our <a href="https://devservices.optionshop.com/docs">docs</a>.</td>
</tr>
<tr>
<td>To learn more about our job opportunities, head to the <a href="http://www.optionscity.com/careers/">OptionsCity jobs</a> section.</td>
</tr>
</table></body></html>'''
# record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(html, 'plain')
part2 = MIMEText(html, 'html')
# attach parts into message container.
msg.attach(part1)
msg.attach(part2)
# send the message via local SMTP server.
s = smtplib.SMTP("smtp.gmail.com", 587)
s.ehlo()
s.starttls()
s.ehlo()
s.login(EMAIL_HOST_USER, EMAIL_HOST_PASSWORD)
s.sendmail(EMAIL_HOST_USER, email_address, msg.as_string())
s.quit()
return jsonify({"success": True})
if __name__ == '__main__':
app.run()