Skip to content
Snippets Groups Projects
Commit f1d32602 authored by Ismailn16's avatar Ismailn16
Browse files

initial email sending function done

parent b4851c51
No related branches found
No related tags found
No related merge requests found
from flask import Flask, render_template, request from flask import Flask, render_template, request
from flask_mail import Mail, Message from flask_mail import Mail, Message
import os
app = Flask(__name__) app = Flask(__name__)
mail = Mail(app)
app.config['MAIL_SERVER'] = 'smtp.gmail.com' app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 587 app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USE_SSL'] = False app.config['MAIL_USE_SSL'] = False
app.config['MAIL_USERNAME'] = 'UWEITSTestEmail@gmail.com' app.config['MAIL_USERNAME'] = 'uweitstestemail@gmail.com'
app.config['MAIL_PASSWORD'] = 'ITPtesting2024' app.config['MAIL_PASSWORD'] = os.environ.get('its_password')
mail = Mail(app)
@app.route('/home') @app.route('/home', methods=['GET', 'POST'])
@app.route('/') @app.route('/')
def home(): def home():
return render_template('test.html') return render_template('test.html')
#def send_email(): @app.route('/process_form', methods=['POST'])
# user_firstname = request.form('firstname') def process_data():
# user_lastname = request.form('lastname') user_firstname = request.form['firstname']
# user_email = request.form('UWEemail') user_lastname = request.form['lastname']
# user_issue = request.form('issue') user_email = request.form['UWEemail']
# user_info = request.form('furtherinfo') user_issue = request.form['issue']
user_info = request.form['furtherinfo']
# if 'live.uwe.ac.uk' in user_email: result = send_email(user_email)
# if user_issue == 'issue1':
# if 'password' & 'forgot' in user_info: return result
app.route('/send_email', methods=['POST'])
def send_email(user_email):
if 'live.uwe.ac.uk' in user_email:
msg = Message("UWE ITS Help Service", sender = 'uweitstestemail@gmail.com', recipients = [user_email])
msg.body = "Hi, This is a test email as we are currently prototyping. Thank you for your support."
mail.send(msg)
return "Email sent."
else:
return "This email isn't a UWE Email, Goodbye."
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True) app.run(debug=True, host='0.0.0.0', port=5000)
\ No newline at end of file \ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
</head> </head>
<body> <body>
<form method="post" action=""> <form method="post" action="/process_form">
<div> <div>
<label for="firstname">First Name:</label> <label for="firstname">First Name:</label>
<input type="text" id="firstname" placeholder="Please enter your first name" name="firstname" required> <input type="text" id="firstname" placeholder="Please enter your first name" name="firstname" required>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment