So I added a mailbox to my app using Rail's ActionMailbox. It's set the following way:
A small email server: basically a docker image running Postfix behind a rails-api application with ActionMailbox set-up. Very similar to this: https://github.com/Loumaris/action-mailbox-docker-postfix-relay
The main-app where the internal routing and email processing is set:
class ApplicationMailbox < ActionMailbox::Base routing :all => :imports end class ImportsMailbox < ApplicationMailbox def process ... end end
Now, both apps are deployed in the same cluster (using kubernetes). Each on it's own container. ActionMailbox's config for relay SMTP services is set with:
bin/rails action_mailbox:ingress:postfix URL=https://main-app.com/rails/action_mailbox/relay/inbound_emails INGRESS_PASSWORD=...
The first part works well, the email server pipes emails to the main-app and instances of InboundEmail
objects are created there. The problem is the internal routing (inside main-app) never takes place. Emails are never redirected to ImportsMailbox
to be processed:
class ApplicationMailbox < ActionMailbox::Base
routing :all => :imports # this routing never happens
end
Not only this works fine locally, but if I run the main-app from my computer, set a public ngrok host and make email server point at it:
bin/rails action_mailbox:ingress:postfix URL=https://ngrok-host-running-my-local-app.com/rails/action_mailbox/relay/inbound_emails INGRESS_PASSWORD=...
it also works. So the problem might be somewhere within staging env setting.
Some info regarding logs. This is when main-app gets an email:
Jan 26 08:56:46 02877f113fb4 postfix/pipe[2158]: 0BBEC1C95E9: to=<deploy@inbound.main-app.io>, orig_to=<user-something@inbound.main-app.io>, relay=forward_to_rails, delay=2.5, delays=0.38/0.01/0/2.1, dsn=2.0.0, status=sent (delivered via forward_to_rails service (/usr/l
Jan 26 08:56:46 02877f113fb4 postfix/qmgr[103]: 0BBEC1C95E9: removed
Jan 26 09:06:06 02877f113fb4 postfix/qmgr[103]: 80BEF1C95EA: from=<>, size=12504, nrcpt=1 (queue active)
Jan 26 09:06:06 02877f113fb4 postfix/qmgr[103]: 3D15E1C74D7: from=<>, size=28811, nrcpt=1 (queue active)
Jan 26 09:06:06 02877f113fb4 postfix/qmgr[103]: 729111C95E2: from=<>, size=12505, nrcpt=1 (queue active)
Jan 26 09:06:06 02877f113fb4 postfix/qmgr[103]: B75D91C95E6: from=<>, size=6344, nrcpt=1 (queue active)
And right after we see these warnings:
Jan 26 09:06:07 02877f113fb4 postfix/qmgr[103]: warning: private/smtp socket: malformed response
Jan 26 09:06:07 02877f113fb4 postfix/qmgr[103]: warning: transport smtp failure -- see a previous warning/fatal/panic logfile record for the problem description
Jan 26 09:06:07 02877f113fb4 postfix/master[1]: warning: process /usr/lib/postfix/sbin/smtp pid 2166 exit status 1
Jan 26 09:06:07 02877f113fb4 postfix/master[1]: warning: /usr/lib/postfix/sbin/smtp: bad command startup -- throttling
Jan 26 09:06:07 02877f113fb4 postfix/qmgr[103]: warning: private/smtp socket: malformed response
Jan 26 09:06:07 02877f113fb4 postfix/qmgr[103]: warning: transport smtp failure -- see a previous warning/fatal/panic logfile record for the problem description
Jan 26 09:06:07 02877f113fb4 postfix/master[1]: warning: process /usr/lib/postfix/sbin/smtp pid 2167 exit status 1
Jan 26 09:06:07 02877f113fb4 postfix/qmgr[103]: warning: private/smtp socket: malformed response
Jan 26 09:06:07 02877f113fb4 postfix/qmgr[103]: warning: transport smtp failure -- see a previous warning/fatal/panic logfile record for the problem description
Jan 26 09:06:07 02877f113fb4 postfix/master[1]: warning: process /usr/lib/postfix/sbin/smtp pid 2168 exit status 1
config/environments/staging.rb
config.cache_classes = true
# using Postfix for SMTP relay
config.action_mailbox.ingress = :relay
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
config.active_storage.service = ENV.fetch("PRODUCTION_STORAGE_SERVICE") { "production" }.to_sym
config.active_storage.service_urls_expire_in = 30.minutes
config.force_ssl = true
config.log_level = :debug
config.cache_store = :redis_cache_store, { url: ENV["REDIS_INTERNAL_URL"] }
config.active_job.queue_adapter = :sidekiq
config.active_storage.queues.analysis = :low
config.active_storage.queues.purge = :low
config.action_mailer.perform_caching = false
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
config.action_mailer.perform_caching = false
config.action_mailer.default_url_options = { host: ENV["HOST"] }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
address: "smtp.office365.com",
port: 587,
domain: ENV["DOMAIN"],
user_name: ENV["EMAIL_USERNAME"],
password: ENV["EMAIL_PASSWORD"],
authentication: "login",
enable_starttls_auto: true,
}
end
Rails.application.routes.default_url_options[:host] = ENV["INGRESS_HOST"]
Rails.application.routes.default_url_options[:protocol] = "https"