From a6d512ff17b9ff1f13555e6a47555b51573fab86 Mon Sep 17 00:00:00 2001 From: rishi2019194 <58341663+rishi2019194@users.noreply.github.com> Date: Sun, 8 Oct 2023 17:36:42 -0400 Subject: [PATCH] Improved the UI of email notifications --- Code/recommenderapp/app.py | 4 +-- Code/recommenderapp/utils.py | 49 +++++++++++++++++++++++++++++------- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Code/recommenderapp/app.py b/Code/recommenderapp/app.py index c32ba7c33..b10b5f6a6 100644 --- a/Code/recommenderapp/app.py +++ b/Code/recommenderapp/app.py @@ -47,8 +47,8 @@ def search(): @app.route("/feedback", methods=["POST"]) def feedback(): data = json.loads(request.data) - user_email = "ananyamantravadi@gmail.com" - send_email_to_user(user_email, str(beautify_feedback_data(data))) + user_email = "11rishi.singhal@gmail.com" + send_email_to_user(user_email, beautify_feedback_data(data)) return data diff --git a/Code/recommenderapp/utils.py b/Code/recommenderapp/utils.py index ca8abd60b..7afd67298 100644 --- a/Code/recommenderapp/utils.py +++ b/Code/recommenderapp/utils.py @@ -21,14 +21,14 @@ def beautify_feedback_data(data): elif status == 'Dislike': dislike.append(movie) - # Create a plain text string for the categorized data - categorized_data_str = "Movies Yet to Watch:\n" + "\n".join(yet_to_watch) + "\n\n" - categorized_data_str += "Movies Liked:\n" + "\n".join(like) + "\n\n" - categorized_data_str += "Movies Disliked:\n" + "\n".join(dislike) + # Create a category-dictionary of liked, disliked and yet to watch movies + categorized_data_dict = {"Liked":like, "Disliked":dislike, "Yet to Watch":yet_to_watch} - return categorized_data_str + return categorized_data_dict -def send_email_to_user(recipient_email, message_body): + + +def send_email_to_user(recipient_email, categorized_data): """ Utility function to send movie recommendations to user over email """ @@ -44,14 +44,45 @@ def send_email_to_user(recipient_email, message_body): subject = 'Your movie recommendation from PopcornPicks' # Create the email message - message = MIMEMultipart() + message = MIMEMultipart('alternative') message['From'] = sender_email message['To'] = recipient_email message['Subject'] = subject - # Attach the email body - message.attach(MIMEText(message_body, 'plain')) + # Create the email message with HTML content + html_content = """ + + + +

Movie Recommendations from PopcornPicks

+

Dear Movie Enthusiast,

+

We hope you're having a fantastic day!

+
+

Your Movie Recommendations:

+

Movies Liked:

+ +

Movies Disliked:

+ +

Movies Yet to Watch:

+ +
+

Enjoy your movie time with PopcornPicks!

+

Best regards,
PopcornPicks Team

+ + + """.format('\n'.join(f'
  • {movie}
  • ' for movie in categorized_data['Liked']), + '\n'.join(f'
  • {movie}
  • ' for movie in categorized_data['Disliked']), + '\n'.join(f'
  • {movie}
  • ' for movie in categorized_data['Yet to Watch'])) + # Attach the HTML email body + message.attach(MIMEText(html_content, 'html')) + # Connect to the SMTP server try: server = smtplib.SMTP(smtp_server, smtp_port)