From 7849d4d59bc7842f056b8e8b83484cf484cb9d8c Mon Sep 17 00:00:00 2001 From: hdiomede Date: Thu, 26 Oct 2017 17:22:31 -0200 Subject: [PATCH 1/3] excludes directories and other files --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 7bbc71c..c25d88e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ __pycache__/ .Python env/ build/ +bin/ +lib/ +include/ develop-eggs/ dist/ downloads/ @@ -34,6 +37,7 @@ wheels/ # Installer logs pip-log.txt pip-delete-this-directory.txt +pip-selfcheck.json # Unit test / coverage reports htmlcov/ From e260d3a8a00396a1619ab6e1b1bb6ea8e5147b1e Mon Sep 17 00:00:00 2001 From: hdiomede Date: Thu, 26 Oct 2017 17:53:32 -0200 Subject: [PATCH 2/3] adds link to send other email and handles errors --- main.py | 30 +++++++++--------------------- static/style.css | 0 templates/error.html | 6 ++++++ templates/index.html | 11 +++++++++++ templates/layout.html | 13 +++++++++++++ templates/success.html | 6 ++++++ 6 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 static/style.css create mode 100644 templates/error.html create mode 100644 templates/index.html create mode 100644 templates/layout.html create mode 100644 templates/success.html diff --git a/main.py b/main.py index 5364828..1a09579 100644 --- a/main.py +++ b/main.py @@ -1,11 +1,10 @@ import os import sendgrid -from flask import Flask, request +from flask import Flask, request, render_template from sendgrid.helpers.mail import * -SENDGRID_API_KEY = os.environ.get("SENDGRID_API_KEY") - +SENDGRID_API_KEY = "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" app = Flask(__name__) @@ -18,25 +17,14 @@ def mail(): subject = request.form.get("subject") content = Content("text/plain", request.form.get("content")) mail = Mail(from_email, subject, to_email, content) - response = sg.client.mail.send.post(request_body=mail.get()) - if response.status_code == 202: - return "Email sent successfully!" - else: - return "Status Code: " + str(response.status_code) + + try: + response = sg.client.mail.send.post(request_body=mail.get()) + return render_template('success.html') + except: + return render_template('error.html', status_code="400") else: - return """ - - -
-

From:

-

To:

-

Subject:

-

Content:

-

-
- - - """ + return render_template('index.html') if __name__ == "__main__": diff --git a/static/style.css b/static/style.css new file mode 100644 index 0000000..e69de29 diff --git a/templates/error.html b/templates/error.html new file mode 100644 index 0000000..95ce426 --- /dev/null +++ b/templates/error.html @@ -0,0 +1,6 @@ +{% extends "layout.html" %} + +{% block content %} +

Status code: {{ status_code }}

+

Failed to send email

+{% endblock %} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..f6bd154 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,11 @@ +{% extends "layout.html" %} + +{% block content %} +
+

From:

+

To:

+

Subject:

+

Content:

+

+
+{% endblock %} \ No newline at end of file diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..6e8d014 --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,13 @@ + + + + + SENDGRID-FLASK-HEROKU + + +
+ {% block content %} + {% endblock %} +
+ + \ No newline at end of file diff --git a/templates/success.html b/templates/success.html new file mode 100644 index 0000000..6c4ae6d --- /dev/null +++ b/templates/success.html @@ -0,0 +1,6 @@ +{% extends "layout.html" %} + +{% block content %} +

Email sent successfully!

+

Send other email

+{% endblock %} \ No newline at end of file From d20f796bfa8840b5aa7fccb5e3cb65e2e0463ad9 Mon Sep 17 00:00:00 2001 From: hdiomede Date: Thu, 26 Oct 2017 18:02:52 -0200 Subject: [PATCH 3/3] removes credential --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 1a09579..d0502a3 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,7 @@ from flask import Flask, request, render_template from sendgrid.helpers.mail import * -SENDGRID_API_KEY = "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" +SENDGRID_API_KEY = os.environ.get("SENDGRID_API_KEY") app = Flask(__name__)