From be8016725fbe251b5d8837eb8158d9e7ba188b6d Mon Sep 17 00:00:00 2001 From: Ismailn16 <ismailnoor.789@gmail.com> Date: Tue, 13 Feb 2024 02:33:09 +0000 Subject: [PATCH] sendgrid first implementation replaced flaskmail with sendgrid API - first stages --- .gitignore | Bin 0 -> 34 bytes main.py | 24 +++++++++--------------- main2.py | 14 ++++++++++++++ sendgrid.env | Bin 0 -> 196 bytes 4 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 .gitignore create mode 100644 main2.py create mode 100644 sendgrid.env diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..758130a8df9adba0b4edd6c15f39bc74cb4109ae GIT binary patch literal 34 icmezWub3f~A&()2A)TR!A(J76K@ZF?W8h`r0%HKE>IU-w literal 0 HcmV?d00001 diff --git a/main.py b/main.py index 45fbb4f..e7c308c 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 0000000..b68255b --- /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 GIT binary patch literal 196 zcmezWFO{K!p@1Qup@^Y`L4hHd!Ii;}!G*z{A&9|~!G$57!I2?=!IL4L!JEOAA(FwC zL7gF(!JR>mp_0Lp!I&Y3!Gj@>A%#JgA%vll!I>eSA()|xA&kMBA)UdH!IvR|A%h{1 zL60Gq!G|G$A&tR{A%&rgA%ek(A(SDAA(_F0!JNT~p_n0qA&bGC!H6LMY?28>DT6yh sK7$E^AA<>lIYS^rE<-6pHiHvGIzs_N4udH}B!ezPD1$l!F9R0?0FDD7ng9R* literal 0 HcmV?d00001 -- GitLab