#199 Add alternative method to test sending emails
Merged 5 years ago by jflory7. Opened 5 years ago by shraddhaag.
fedora-commops/ shraddhaag/fedora-happiness-packets send-mail  into  master

file modified
+2
@@ -27,6 +27,8 @@ 

      links:

        - db

        - redis

+     # ports:

+     #   - "587:587"

    db:

      image: postgres:10-alpine

      environment:

file modified
+18 -1
@@ -47,7 +47,24 @@ 

  

  Integration tests are run via the following command: ``docker-compose exec web ./manage.py test -v 2 -p integration_test*.py --settings=happinesspackets.settings.tsting``

  

- To test if messages are being sent to the RabbitMQ broker, open a new terminal and run the following command inside the shell of the Docker conatiner `web`::

+ Alternative methods to test sending email

+ -----------------------------------------

+ 

+ In the development environment sending emails is setup in two ways:

+ 

+ * The default setup is to send emails on the console. The settings for the same can be found under the comment ``Configurations for sending email on console``. To see this in action, no changes to the present code base is needed. 

+ 

+ * Emails are also configured to send using Gmail SMTP server. To test this functionality:

+ 

+   1. In ``settings/dev.py`` un-comment the setting for ``Configurations to test sending emails using Gmail SMTP`` and comment out the setting under ``Configurations for sending email on console`` and in ``docker-compose.yml`` un-comment the ports setting in ``celery`` service.

+   2. Enable `less secure apps <https://myaccount.google.com/lesssecureapps>`_ in the Gmail account which you want to use as the host email. 

+      (It is strongly recommended to not allow less secure apps in your primary Gmail account. A separate account for testing is recommended with this setting enabled.)

+   3. Replace ``<HOST@EMAIL.COM>`` and ``<HOST_EMAIL_PASSWORD>`` with the email address of the above account and its password.

+ 

+ Testing Fedora Messaging Integration

+ --------------------------------------

+ 

+ To test if messages are being sent to the RabbitMQ broker, open a new terminal and run the following command inside the shell of the Docker container `web`::

  

      fedora-messaging consume --callback=fedora_messaging.example:printer

  

@@ -21,9 +21,19 @@ 

      }

  }

  

+ #Configurations to send email on console

  CELERY_EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

  EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

  

+ #Configurations to test sending emails using Gmail SMTP

+ # CELERY_EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"

+ # EMAIL_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'

+ # EMAIL_HOST = 'smtp.gmail.com'

+ # EMAIL_HOST_USER = '<HOST@EMAIL.COM>'

+ # EMAIL_HOST_PASSWORD = '<HOST_EMAIL_PASSWORD>'

+ # EMAIL_USE_TLS = True

+ # EMAIL_PORT = 587

+ 

  

  SECRET_KEY = 'only-for-testing'

  

This commit adds the configurations to test sending emails using Gmail's SMTP server.

To test these changes:

  1. In settings/dev.py un-comment the Configurations to test sending emails using Gmail SMTP and comment out the Configurations for sending email on console and in docker-compose.yml un-comment the ports in celery service.
  2. Allow less secure apps in the Gmail accont which is to be used here.
    (It is strongly recommended to not allow less secure apps in your primary Gmail account. A separate account for testing is recommended with this setting enabled.)
  3. Replace <HOST@EMAIL.COM> and <HOST_EMAIL_PASSWORD> with the email address of the above account and its password.

@jflory7 Please find the time to review :)

I didn't remove the setting for sending emails on console since that makes more sense in a development environment as it will not lead to a cluster in Inbox. Please let me know if I need to revert that.

Also, if this works out, should I add the above steps in the documentation for others to refer to, should they choose to test this functionality?

Metadata Update from @jflory7:
- Pull-request tagged with: PASSED, improvement, needs testing, type - backend, type - quality assurance
- Request assigned

5 years ago

@jflory7 Please find the time to review :)

This wasn't as big of a change as I thought, actually this is easy to review!

I didn't remove the setting for sending emails on console since that makes more sense in a development environment as it will not lead to a cluster in Inbox. Please let me know if I need to revert that.

I agree this makes sense. :thumbsup:

Also, if this works out, should I add the above steps in the documentation for others to refer to, should they choose to test this functionality?

Yes. Actually this is the only feedback I have for this PR – it would be great if you could update the development environment instructions with an explanation of the two ways to test email functionality (i.e. basically what you wrote in the original comment in this ticket, but maybe an explanation of testing the console method too).

I think for now, you only need to update the "default" dev environment page and not the Windows-only page. Eventually, I want to reorganize the docs so only the Windows-specific variations from our default instructions on that page (so we aren't writing the same documentation twice). I need to get these thoughts into a new ticket.

Anyways this is a long way of me saying don't worry about cleaning up the docs in this PR, but you only have to include docs on the default dev environment docs page.

Metadata Update from @jflory7:
- Pull-request untagged with: needs testing
- Pull-request tagged with: needs changes, type - docs

5 years ago

rebased onto a3c209ef2a3bacd7c5843edd521350b00c366578

5 years ago

rebased onto f8397e2

5 years ago

@jflory7 I've included the addition to the docs in this PR itself. I hope the way it's worded is easy enough to follow. Please let me know if I need to revise it.

@shraddhaag Excellent. This looks great! Thanks for working on this. Merging! :checkered_flag:

Pull-Request has been merged by jflory7

5 years ago