Repository: zulip/zulip

Issue:
prod install fails if EMAIL_HOST isn't set
The comment in settings.py says you can leave EMAIL_HOST commented out, but when you try to initialize the database, you get an exception complaining EMAIL_HOST isn't defined. 

Is the comment incorrect? Or should this work?

```
# Configure the outgoing SMTP server below. For testing, you can skip                      
# sending emails entirely by commenting out EMAIL_HOST, but you will                       
# want to configure this to support email address confirmation emails,                     
# missed message emails, onboarding follow-up emails, etc. To                              
# configure SMTP, you will need to complete the following steps:                           
#                                                                                          
# (1) Fill out the outgoing email sending configuration below.                             
#                                                                                          
# (2) Put the SMTP password for EMAIL_HOST_USER in                                         
# /etc/zulip/zulip-secrets.conf as email_password.                                         
#                                                                                          
# (3) If you are using a gmail account to send outgoing email, you                         
# will likely need to read this Google support answer and configure                        
# that account as "less secure":                                                           
# https://support.google.com/mail/answer/14257.                                            
#                                                                                          
# You can quickly test your sending email configuration using:                             
#   su zulip                                                                               
#   /home/zulip/deployments/current/manage.py send_test_email username@example.com         
#                                                                                          
# A common problem is hosting providers that block outgoing SMTP traffic.                  
#                                                                                          
# With the exception of reading EMAIL_HOST_PASSWORD from                                   
# email_password in the Zulip secrets file, Zulip uses Django's                            
# standard EmailBackend, so if you're having issues, you may want to                       
# search for documentation on using your email provider with Django.                       
```

```
root@minmi:~# su zulip -c /home/zulip/deployments/current/scripts/setup/initialize-database++ dirname /home/zulip/deployments/current/scripts/setup/initialize-database
+ cd /home/zulip/deployments/current/scripts/setup/../..
+ ./manage.py checkconfig
Traceback (most recent call last):
  File "/home/zulip/deployments/2017-02-14-00-03-09/scripts/lib/log-management-command", line 15, in <module>
    if not os.path.exists(settings.MANAGEMENT_LOG_PATH):
  File "/home/zulip/deployments/2017-02-14-00-03-09/zulip-venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/home/zulip/deployments/2017-02-14-00-03-09/zulip-venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/home/zulip/deployments/2017-02-14-00-03-09/zulip-venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/zulip/deployments/2017-02-14-00-03-09/zproject/settings.py", line 1098, in <module>
    if not EMAIL_HOST and PRODUCTION:
NameError: name 'EMAIL_HOST' is not defined
Traceback (most recent call last):
  File "./manage.py", line 22, in <module>
    " ".join(sys.argv)])
  File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/home/zulip/deployments/2017-02-14-00-03-09/scripts/lib/log-management-command', './manage.py checkconfig']' returned non-zero exit status 1
```



Discussion:
Nice find.  I think we just need to add `EMAIL_HOST` with a default of None in DEFAULT_SETTINGS.
`'EMAIL_HOST': None` in the Django settings.py does let you get past that error. But you still need the confirmation email to finish creating your realm. I looked to see if it was logged, but I didn't see where. 

After trying it, I think the comment is too encouraging. I set up working SMTP anyway to get the confirmation email.

If providing an easier "for testing" path is a goal, I'd rather have specific instructions for that. For example, it could include how to do it without real SSL certs and domain name. (Which is only noted at the bottom of the SSL certs page.)
Yeah, I think the comment is out of date; it predates the `manage.py generate_realm_creation_link` flow.

Resolving patch:
diff --git a/zproject/prod_settings_template.py b/zproject/prod_settings_template.py
--- a/zproject/prod_settings_template.py
+++ b/zproject/prod_settings_template.py
@@ -68,21 +68,23 @@
 # SSO_APPEND_DOMAIN = "example.com")
 SSO_APPEND_DOMAIN = None # type: str
 
-# Configure the outgoing SMTP server below. For testing, you can skip
-# sending emails entirely by commenting out EMAIL_HOST, but you will
-# want to configure this to support email address confirmation emails,
-# missed message emails, onboarding follow-up emails, etc. To
-# configure SMTP, you will need to complete the following steps:
+# Configure the outgoing SMTP server below. You will need working
+# SMTP to complete the installation process, in addition to sending
+# email address confirmations, missed message notifications, onboarding
+# follow-ups, and other user needs. If you do not have an SMTP server
+# already, we recommend services intended for developers such as Mailgun.
+#
+# To configure SMTP, you will need to complete the following steps:
 #
 # (1) Fill out the outgoing email sending configuration below.
 #
 # (2) Put the SMTP password for EMAIL_HOST_USER in
 # /etc/zulip/zulip-secrets.conf as email_password.
 #
-# (3) If you are using a gmail account to send outgoing email, you
+# If you are using a gmail account to send outgoing email, you
 # will likely need to read this Google support answer and configure
 # that account as "less secure":
-# https://support.google.com/mail/answer/14257.
+# https://support.google.com/accounts/answer/6010255
 #
 # You can quickly test your sending email configuration using:
 #   su zulip
diff --git a/zproject/settings.py b/zproject/settings.py
--- a/zproject/settings.py
+++ b/zproject/settings.py
@@ -108,6 +108,7 @@ def get_secret(key):
                     'EMAIL_GATEWAY_IMAP_PORT': None,
                     'EMAIL_GATEWAY_IMAP_FOLDER': None,
                     'EMAIL_GATEWAY_EXTRA_PATTERN_HACK': None,
+                    'EMAIL_HOST': None,
                     'S3_KEY': '',
                     'S3_SECRET_KEY': '',
                     'S3_AVATAR_BUCKET': '',


Test patch: