Repository: fossasia/open-event-server

Issue:
Sent out Email Info missing in Admin Logs
According to the logs page in the admin area, emails were sent out, but it does not show up where the emails have been sent to.

![screenshot from 2016-07-09 18 03 38](https://cloud.githubusercontent.com/assets/1583873/16708803/a178dc90-45ff-11e6-8141-80dcb1c8a199.png)



Discussion:

Resolving patch:
diff --git a/open_event/helpers/data.py b/open_event/helpers/data.py
--- a/open_event/helpers/data.py
+++ b/open_event/helpers/data.py
@@ -364,18 +364,19 @@ def add_session_to_event(request, event_id, state=None):
 
         invite_emails = form.getlist("speakers[email]")
         for index, email in enumerate(invite_emails):
-            new_invite = Invite(event_id=event_id,
-                                session_id=new_session.id)
-            hash = random.getrandbits(128)
-            new_invite.hash = "%032x" % hash
-            save_to_db(new_invite, "Invite saved")
-
-            link = url_for('event_sessions.invited_view', session_id=new_session.id, event_id=event_id, _external=True)
-            Helper.send_email_invitation(email, new_session.title, link)
-            # If a user is registered by the email, send a notification as well
-            user = DataGetter.get_user_by_email(email, no_flash=True)
-            if user:
-                Helper.send_notif_invite_papers(user, event.name, link)
+            if not string_empty(email):
+                new_invite = Invite(event_id=event_id,
+                                    session_id=new_session.id)
+                hash = random.getrandbits(128)
+                new_invite.hash = "%032x" % hash
+                save_to_db(new_invite, "Invite saved")
+
+                link = url_for('event_sessions.invited_view', session_id=new_session.id, event_id=event_id, _external=True)
+                Helper.send_email_invitation(email, new_session.title, link)
+                # If a user is registered by the email, send a notification as well
+                user = DataGetter.get_user_by_email(email, no_flash=True)
+                if user:
+                    Helper.send_notif_invite_papers(user, event.name, link)
 
 
     @staticmethod
diff --git a/open_event/helpers/helpers.py b/open_event/helpers/helpers.py
--- a/open_event/helpers/helpers.py
+++ b/open_event/helpers/helpers.py
@@ -217,29 +217,30 @@ def send_email(to, action, subject, html):
     """
     Sends email and records it in DB
     """
-    key = get_settings()['sendgrid_key']
-    if not key:
-        print 'Sendgrid key not defined'
-        return
-    headers = {
-        "Authorization": ("Bearer " + key)
-    }
-    payload = {
-        'to': to,
-        'from': 'open-event@googlegroups.com',
-        'subject': subject,
-        'html': html
-    }
-    requests.post("https://api.sendgrid.com/api/mail.send.json",
-                  data=payload,
-                  headers=headers)
-    # record_mail(to, action, subject, html)
-    mail = Mail(
-        recipient=to, action=action, subject=subject,
-        message=html, time=datetime.now()
-    )
-    from data import save_to_db
-    save_to_db(mail, 'Mail Recorded')
+    if not string_empty(to):
+        key = get_settings()['sendgrid_key']
+        if not key:
+            print 'Sendgrid key not defined'
+            return
+        headers = {
+            "Authorization": ("Bearer " + key)
+        }
+        payload = {
+            'to': to,
+            'from': 'open-event@googlegroups.com',
+            'subject': subject,
+            'html': html
+        }
+        requests.post("https://api.sendgrid.com/api/mail.send.json",
+                      data=payload,
+                      headers=headers)
+        # record_mail(to, action, subject, html)
+        mail = Mail(
+            recipient=to, action=action, subject=subject,
+            message=html, time=datetime.now()
+        )
+        from data import save_to_db
+        save_to_db(mail, 'Mail Recorded')
     return
 
 #################


Test patch: