-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail.py
34 lines (28 loc) · 931 Bytes
/
email.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
from flask import Flask, render_template, request
from flask_mail import Mail, Message
app = Flask(__name__)
# configure Flask-Mail with your email server settings
app.config['MAIL_SERVER']='smtp.mailtrap.io'
app.config['MAIL_PORT'] = 2525
app.config['MAIL_USERNAME'] = '59716b937de272'
app.config['MAIL_PASSWORD'] = '76542f00ee4401'
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USE_SSL'] = False
mail = Mail(app)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/send-email', methods=['POST'])
def send_email():
subject = request.form['subject']
sender = request.form['sender']
recipient = request.form['recipient']
body = request.form['body']
msg = Message(subject=subject,
sender=sender,
recipients=[recipient])
msg.body = body
mail.send(msg)
return 'Email sent!'
if __name__ == '__main__':
app.run(debug=True)