[#139] Send conversation emails (#442)

* [#139] Delayed emails for conversations

* Added the setex and get methods to Redis wrapper
* Set the priorities for the sidekiq queues
* Was not able to use mailhog for testing email in local, switched back to letter opener and added comments on using the SMTP settings
* Added after create hood in messages to queue the sending of mail after 2 minutes using sidekiq worker and also set the redis key for the conversation to avoid the email sending for every message
* Added the sidekiq worker to send the email and delete the conversation redis key
* Added the mailer and mail template
* mailer sends the last 10 messages along with the new messages from the time it was queued

* Send email only in development or if smtp config is set

* Send email only in development or if smtp config is set
* Set the SMTP_PORT in production variable

* Adding redis to circle CI

* Specs for the conversation email changes

* Added specs for conversation email sidekiq worker
* Added specs for conversation mailer
* Added specs in message model for the after create hook for notify email

* Send emails only when there is a reply from agent

* set development to use mailhog

* Adding comments for using letter opener
This commit is contained in:
Sony Mathew
2020-01-23 23:14:07 +05:45
committed by Sojan Jose
parent 1d3ed016be
commit d4b3ba4baa
18 changed files with 184 additions and 13 deletions

View File

@@ -34,7 +34,7 @@ Rails.application.configure do
# Don't care if the mailer can't send.
config.active_job.queue_adapter = :sidekiq
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
@@ -42,13 +42,17 @@ Rails.application.configure do
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host: 'localhost:3000' }
# If you want to use letter opener instead of mailhog for testing emails locally,
# uncomment the following line L49 and comment lines L51 through to L65
# config.action_mailer.delivery_method = :letter_opener
config.action_mailer.delivery_method = :smtp
smtp_settings = {
port: ENV['SMTP_PORT'],
domain: ENV['SMTP_DOMAIN'],
address: ENV['SMTP_ADDRESS']
port: ENV['SMTP_PORT'] || 25,
domain: ENV['SMTP_DOMAIN'] || 'localhost',
address: ENV['SMTP_ADDRESS'] || 'chatwoot.com'
}
if ENV['SMTP_AUTHENTICATION'].present?

View File

@@ -59,7 +59,7 @@ Rails.application.configure do
config.action_mailer.default_url_options = { host: ENV['FRONTEND_URL'] }
config.action_mailer.smtp_settings = {
address: ENV['SMTP_ADDRESS'],
port: 587,
port: ENV['SMTP_PORT'] || 587,
user_name: ENV['SMTP_USERNAME'],
password: ENV['SMTP_PASSWORD'],
authentication: :login,

View File

@@ -2,5 +2,6 @@ uri = URI.parse(ENV.fetch('REDIS_URL', 'redis://127.0.0.1:6379'))
redis = Rails.env.test? ? MockRedis.new : Redis.new(url: uri)
Nightfury.redis = Redis::Namespace.new('reports', redis: redis)
# Alfred - Used currently for Round Robin. Add here as you use it for more features
# Alfred - Used currently for round robin and conversation emails.
# Add here as you use it for more features
$alfred = Redis::Namespace.new('alfred', redis: redis, warning: true)

View File

@@ -11,10 +11,10 @@
# even put in dynamic logic, like a host-specific queue.
# http://www.mikeperham.com/2013/11/13/advanced-sidekiq-host-specific-queues/
:queues:
- critical
- default
- low
- mailers
- [critical, 5]
- [default, 2]
- [low, 1]
- [mailers, 2]
# you can override concurrency based on environment
production: