Skip to content

Instantly share code, notes, and snippets.

@lozadaOmr
Created September 11, 2015 06:15
Show Gist options
  • Save lozadaOmr/31cb09db540b72fc36f3 to your computer and use it in GitHub Desktop.
Save lozadaOmr/31cb09db540b72fc36f3 to your computer and use it in GitHub Desktop.
# Maybe just use /send endpoint
# Since we dont want to break stuff use different we use route
@app.route('/reset_password', methods=['GET', 'POST'])
def reset_password():
# Create message container - the correct MIME type is
# multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Link"
# Create the body of the message (a plain-text and an HTML version).
text = "Hi!\nHow are you?\nHere is the link you wanted:\nhttp://www.python.org"
html = """\
<html>
<head></head>
<body>
<p>Hi!<br>
How are you?<br>
Here is the <a href="http://www.python.org">link</a> you wanted.
</p>
</body>
</html>
"""
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
msg.attach(part2)
fromaddr = '[email protected]'
smtp_server = 'email-smtp.us-east-1.amazonaws.com'
smtp_username = 'AKIAJBB735J6LY4FGMGA'
smtp_password = 'AjT+4L4gI0pqpaHRxMpMy7bggNFMuE19jKhe64WwljI9'
smtp_port = '587'
smtp_do_tls = True
token = request.args.get('token')
email_address = request.args.get('email_address')
print '** Connecting to SMTP'
server = smtplib.SMTP(
host=smtp_server,
port=smtp_port,
timeout=10
)
server.set_debuglevel(10)
server.starttls()
server.ehlo()
print '** Login to SMTP'
server.login(smtp_username, smtp_password)
print '** Sending Email to', email_address
server.sendmail(
fromaddr, email_address, msg.as_string())
server.quit()
return jsonify({'result': 'success'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment