Repository: fossasia/open-event-server

Issue:
After-Event Mail: Separate Email Template of Speaker and Owner/Organizer
There is an after-event message, that should not go to the speaker and organizer at the same time, which can be viewed at https://eventyay.com/admin/messages/list .

![Screenshot from 2019-09-16 10-59-01](https://user-images.githubusercontent.com/1583873/64946703-c20d4900-d873-11e9-9e2d-e07f22fefc0c.png)

Instead there should be
a) a message to the owner and organizers
b) a message to the speaker
These message should be differently and don't include upcoming events.

1. Please implement a message to the "Owner, Organizer"
Subject: {eventname} is over. Thank you for using Eventyay!
Email: Hi {email}, you event {eventname] is over. Thank you for using the Eventyay platform for your event. We hope you enjoyed it. 

2. Implement a message only for accepted speakers
Subject: {eventname} is over. Thank you for participating!
Email: Hi {email},thank you for participating in our {eventname]. We hope you enjoyed it and keep in touch.



Discussion:
I am taking this up!
@iamareebjamal  Hey I need to work in which file plz help me I started checking all files ?

Means I need to change the message ?? 


Resolving patch:
diff --git a/app/api/helpers/mail.py b/app/api/helpers/mail.py
--- a/app/api/helpers/mail.py
+++ b/app/api/helpers/mail.py
@@ -730,3 +730,35 @@ def send_email_to_moderator(video_stream_moderator):
             settings=get_settings(),
         ),
     )
+
+
+def send_email_after_event(email, event_name):
+    action = MailType.AFTER_EVENT
+    mail = MAILS[action]
+
+    send_email(
+        to=email,
+        action=action,
+        subject=mail['subject'].format(event_name=event_name),
+        html=render_template(
+            mail['template'],
+            email=email,
+            eventname=event_name,
+        ),
+    )
+
+
+def send_email_after_event_speaker(email, event_name):
+    action = MailType.AFTER_EVENT_SPEAKER
+    mail = MAILS[action]
+
+    send_email(
+        to=email,
+        action=action,
+        subject=mail['subject'].format(event_name=event_name),
+        html=render_template(
+            mail['template'],
+            eventname=event_name,
+            email=email,
+        ),
+    )
diff --git a/app/api/helpers/scheduled_jobs.py b/app/api/helpers/scheduled_jobs.py
--- a/app/api/helpers/scheduled_jobs.py
+++ b/app/api/helpers/scheduled_jobs.py
@@ -8,6 +8,8 @@
 
 from app.api.helpers.db import save_to_db
 from app.api.helpers.mail import (
+    send_email_after_event,
+    send_email_after_event_speaker,
     send_email_ticket_sales_end,
     send_email_ticket_sales_end_next_week,
     send_email_ticket_sales_end_tomorrow,
@@ -118,23 +120,22 @@ def send_after_event_mail():
         speakers = Speaker.query.filter_by(event_id=event.id, deleted_at=None).all()
         owner = get_user_event_roles_by_role_name(event.id, 'owner').first()
         unique_emails = set()
-        user_objects = []
+        unique_emails_speakers = set()
         for speaker in speakers:
             if not speaker.is_email_overridden:
-                unique_emails.add(speaker.user.email)
-                user_objects.append(speaker.user)
+                unique_emails_speakers.add(speaker.user.email)
+
         for organizer in organizers:
             unique_emails.add(organizer.user.email)
-            user_objects.append(organizer.user)
+
         if owner:
             unique_emails.add(owner.user.email)
-            user_objects.append(owner.user)
-        # for email in unique_emails:
-        #     send_email_after_event(email, event.name, frontend_url)
-        #  Unique user's dict based on their id.
-        # unique_users_dict = make_dict(user_objects, "id")
-        # for user in unique_users_dict.values():
-        #     send_notif_after_event(user, event.name)
+
+        for email in unique_emails:
+            send_email_after_event(email, event.name)
+
+        for email in unique_emails_speakers:
+            send_email_after_event_speaker(email, event.name)
 
 
 @celery.task(base=RequestContextTask, name='change.session.state.on.event.completion')
@@ -209,7 +210,11 @@ def send_event_fee_notification_followup(follow_up=True):
         logger.warning('Not valid follow up request: %s', follow_up)
         return
     query = EventInvoice.query.filter(
-        EventInvoice.amount > 0, EventInvoice.status != 'paid', EventInvoice.status != 'resolved', EventInvoice.status != 'refunded', EventInvoice.status != 'refunding'
+        EventInvoice.amount > 0,
+        EventInvoice.status != 'paid',
+        EventInvoice.status != 'resolved',
+        EventInvoice.status != 'refunded',
+        EventInvoice.status != 'refunding',
     )
     this_month = this_month_date()
     if follow_up != 'post_due':
diff --git a/app/api/helpers/system_mails.py b/app/api/helpers/system_mails.py
--- a/app/api/helpers/system_mails.py
+++ b/app/api/helpers/system_mails.py
@@ -27,6 +27,8 @@ class MailType:
     EVENT_IMPORTED = 'event_imported'
     EVENT_IMPORT_FAIL = 'event_import_fail'
     MONTHLY_PAYMENT = 'monthly_payment'
+    AFTER_EVENT = 'after_event'
+    AFTER_EVENT_SPEAKER = 'after_event_speaker'
     MONTHLY_PAYMENT_FOLLOWUP = 'monthly_payment_follow_up'
     MONTHLY_PAYMENT_PRE_DUE = 'monthly_payment_pre_due'
     MONTHLY_PAYMENT_POST_DUE = 'monthly_payment_post_due'
@@ -275,4 +277,14 @@ def entries():
         'subject': 'Join {event_name} from {group_name} on {event_date}',
         'template': 'email/announce_event.html',
     },
+    MailType.AFTER_EVENT: {
+        'recipient': 'Owner, Organizer, Coorganizer',
+        'subject': '{event_name} is over. Thank you for using eventyay!',
+        'template': 'email/after_event.html',
+    },
+    MailType.AFTER_EVENT_SPEAKER: {
+        'recipient': 'User',
+        'subject': '{event_name} is over. Thank you for participating!',
+        'template': 'email/after_event_speaker.html',
+    },
 }


Test patch: