diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..758130a8df9adba0b4edd6c15f39bc74cb4109ae Binary files /dev/null and b/.gitignore differ diff --git a/main.py b/main.py index 45fbb4f0c757cf6648a50d0dc6d5a5fd974268c5..e7c308c41e5688dd8e9c7cc7dd7e97519494d8fe 100644 --- a/main.py +++ b/main.py @@ -1,18 +1,9 @@ from flask import Flask, render_template, request -from flask_mail import Mail, Message -import os +import sendgrid +from sendgrid.helpers.mail import * app = Flask(__name__) -mail = Mail(app) - -app.config['MAIL_SERVER'] = 'smtp.gmail.com' -app.config['MAIL_PORT'] = 587 -app.config['MAIL_USE_TLS'] = True -app.config['MAIL_USE_SSL'] = False -app.config['MAIL_USERNAME'] = 'uweitstestemail@gmail.com' -app.config['MAIL_PASSWORD'] = os.environ.get('its_password') -#os.environ.get('its_password') -mail = Mail(app) +sg = sendgrid.SendGridAPIClient('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') @app.route('/home', methods=['GET', 'POST']) @app.route('/') @@ -36,9 +27,12 @@ def process_data(): app.route('/send_email', methods=['POST']) def send_email(user_email, user_firstname, user_lastname): - msg = Message("UWE ITS Help Service", sender = 'uweitstestemail@gmail.com', recipients = [user_email]) - msg.body = "Hi " + user_firstname + " " + user_lastname + ", This is a test email as we are currently prototyping. Thank you for your support." - mail.send(msg) + from_email = 'uweitstestemail@gmail.com' + to_email = To(user_email) + subject = "UWE ITS Test Email" + content = Content("text/plain", "Hi " + user_firstname + " " + user_lastname + ", This is a test email as we are currently prototyping this system. Thank you for your support!") + mail = Mail(from_email, to_email, subject, content) + response = sg.client.mail.send.post(request_body=mail.get()) return "The email has been sent. Please check your junk if it has not appeared in your inbox." diff --git a/main2.py b/main2.py new file mode 100644 index 0000000000000000000000000000000000000000..b68255b20dd22e77ad9a41a2095f068b0e9c6c22 --- /dev/null +++ b/main2.py @@ -0,0 +1,14 @@ +import sendgrid +import os +from sendgrid.helpers.mail import * + +sg = sendgrid.SendGridAPIClient('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') +from_email = Email('uweitstestemail@gmail.com') +to_email = To('ismailnoor.102@gmail.com') +subject = "Sending with SendGrid is Fun" +content = Content("text/plain", "and easy to do anywhere, even with Python") +mail = Mail(from_email, to_email, subject, content) +response = sg.client.mail.send.post(request_body=mail.get()) +print(response.status_code) +print(response.body) +print(response.headers) \ No newline at end of file diff --git a/sendgrid.env b/sendgrid.env new file mode 100644 index 0000000000000000000000000000000000000000..f3cd8817d358e5aa1922b95483ada2b23fe212ff Binary files /dev/null and b/sendgrid.env differ