Repository: fossasia/open-event-server

Issue:
Event Export: Celery export tries to access SMTP Configs
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
Event Export tries to access SMTP Configs

**To Reproduce**

Steps to reproduce the behavior:

- Don't fill SMPT Configs.
- Try Export Event, See Stack Trace

**Expected behaviour**
<!-- A clear and concise description of what you expected to happen. -->

It should not access SMTP

**Stacktrace**
<!-- If applicable, add stack trace to help explain your problem. -->
```py
File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py", line 336, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py", line 1039, in _get_socket
    server_hostname=self._host)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 846, in _create
    owner=self, session=self._session,
ValueError: server_hostname cannot be an empty string or start with a leading dot.
```

**Additional details (please complete the following information):**
 - OS: MacOS
 - Python Version 3.7



Discussion:
Will work on this.
@kushthedude I've taken a look at this and found out that the issue is corresponding to the export mail which is being sent out. 

Resolving patch:
diff --git a/app/api/helpers/tasks.py b/app/api/helpers/tasks.py
--- a/app/api/helpers/tasks.py
+++ b/app/api/helpers/tasks.py
@@ -17,7 +17,7 @@
 from app.api.helpers.utilities import strip_tags
 from app.models.session import Session
 from app.models.speaker import Speaker
-
+from app.api.helpers.mail import check_smtp_config
 
 """
 Define all API v2 celery tasks here
@@ -174,6 +174,7 @@ def resize_speaker_images_task(self, speaker_id, photo_url):
 def export_event_task(self, email, event_id, settings):
     event = safe_query(db, Event, 'id', event_id, 'event_id')
     user = db.session.query(User).filter_by(email=email).first()
+    smtp_encryption = get_settings()['smtp_encryption']
     try:
         logging.info('Exporting started')
         path = event_export_task_base(event_id, settings)
@@ -183,15 +184,21 @@ def export_event_task(self, email, event_id, settings):
         result = {
             'download_url': download_url
         }
+
         logging.info('Exporting done.. sending email')
-        send_export_mail(email=email, event_name=event.name, download_url=download_url)
+        if check_smtp_config(smtp_encryption):
+            send_export_mail(email=email, event_name=event.name, download_url=download_url)
+        else:
+            logging.warning('Error in sending export success email')
         send_notif_after_export(user=user, event_name=event.name, download_url=download_url)
     except Exception as e:
         result = {'__error': True, 'result': str(e)}
         logging.warning('Error in exporting.. sending email')
-        send_export_mail(email=email, event_name=event.name, error_text=str(e))
+        if check_smtp_config(smtp_encryption):
+            send_export_mail(email=email, event_name=event.name, error_text=str(e))
+        else:
+            logging.warning('Error in sending export error email')
         send_notif_after_export(user=user, event_name=event.name, error_text=str(e))
-
     return result
 
 


Test patch: