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/ diff --git a/main.py b/main.py index 5364828..d0502a3 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") - 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