Hello, I'm trying to setup my solidus app in produ...
# support
s
Hello, I'm trying to setup my solidus app in production mode, I did
RAILS_ENV=production rails db:setup
, for the admin user I entered something like 'user@mywebdomain.net' for the Email/login but I got :
Copy code
rails aborted!
Net::SMTPFatalError: <store@example.com>: Sender address rejected: Domain <http://example.com|example.com> does not accept mail (nullMX)
/home/computer/shop/db/seeds.rb:10:in `main`
PS. I'm using solidus_core 3.2.2 && solidus_auth_devise 2.5.4
1
w
It looks like you haven’t configured your email provider. You can take a look at https://guides.solidus.io/getting-started/deploying-your-store#email-delivery.
s
Oh ok, it must be in
config/application.rb
? because I did in
config/environments/production.rb
w
It should work both ways
Can you share your config (hiding secrets, of course)?
👍 1
s
'environments/production.rb'
Copy code
Rails.application.configure do

...

  # SMTP Config
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.perform_caching = true
  config.action_mailer.raise_delivery_errors = true
  
  config.action_mailer.smtp_settings = {
	address: '<http://mail.gandi.net|mail.gandi.net>',
	port: 465,
	domain: '<http://gandi.net|gandi.net>',
	user_name: Rails.application.credentials.mail[:username],
	password: Rails.application.credentials.mail[:password],
	authentication: 'plain',
	ssl: true,
	tsl: true,
	enable_starttls_auto: true
  }

...

end
Does the admin's mail have to be the same than the email (user_name) configured in the SMTP config ?
w
I don’t think your problem is related to Solidus…
What do you have in
/home/computer/shop/db/seeds.rb:10
?
s
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
in full :
Copy code
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
#   movies = Movie.create([{ name: "Star Wars" }, { name: "Lord of the Rings" }])
#   Character.create(name: "Luke", movie: movies.first)

Spree::Core::Engine.load_seed if defined?(Spree::Core)
Spree::Auth::Engine.load_seed if defined?(Spree::Auth)
w
solidus_auth_devise
seeds don’t seem like being messing with email configuration: https://github.com/solidusio/solidus_auth_devise/blob/master/db/default/users.rb
Can you run the Rails console in production and confirm that your email settings are being picked?
For instance, is `Rails.application.config.action_mailer.smtp_settings[:domain]`returning
<http://gandi.net|gandi.net>
?
s
Yes it's returning
<http://gandi.net|gandi.net>
Copy code
$ RAILS_ENV=production rails c
Loading production environment (Rails 7.0.4)
irb(main):001:0> Rails.application.config.action_mailer.smtp_settings[:domain]
=> "<http://gandi.net|gandi.net>"
In
initializers/spree.rb
I have something like this
config.mails_from = "<mailto:user@mywebdomain.net|user@mywebdomain.net>"
w
All right, I think I know what’s going on. With
db:setup
you’re trying to load all the sample data usually consumed only in development. That includes a sample store setting
<mailto:store@example.com|store@example.com>
as the
Store#mail_from_address
. However, you’re already configuring the mail server for production. You have two options: • If you don’t want the sample data in production, instead of
db:setup
run: ◦
bin/rails db:create
bin/rails db:schema:load
◦ `bin/rails spree_authadmincreate`to create an admin user • If you do want the sample data in production, you need to create a sample store with a
#mail_from_address
that will work in your case. E.g., from the console (
bin/rails console
): ◦
Spree::Store.create(code: 'sample-store', name: 'Sample Store', url: '<http://sample_url.com>', mail_from_address: '<mailto:real_address@gandi.net|real_address@gandi.net>')
It’s essential that the code is
sample-store
(so that Solidus skips creating it) and that
mail_from_address
is your actual email address. ◦ After that, you should be able to run
bin/rails db:setup
.
s
Thank you very much @waiting_for_dev ! It's working fine 🙂 I naively thought that in production mode the sample data will not be loaded :x
I have still this error (because I have Devise confirmable ?)
Copy code
rails aborted!
ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
/home/computer/shop/app/mailers/spree/user_mailer.rb:14:in `confirmation_instructions'
I added
config.action_mailer.default_url_options = { :host => "mywebdomain" }
in
environments/production.rb
but I still got the same error
w
Please, try with `
Copy code
Rails.application.routes.default_url_options[:host] = "<http://mywebdomain.com|mywebdomain.com>"
s
I added in
Rails.application.routes.default_url_options[:host] = "<http://mywebdomain.com|mywebdomain.com>"
in
environments/production.rb
it's still the same error. Maybe I should create a store before run
rails spree_auth:admin:create
?
w
Weird. Please, could you copy the contents of
/home/computer/shop/app/mailers/spree/user_mailer.rb:14
. I think I know what it contains, but only to confirm.
s
@confirmation_url = spree.spree_user_confirmation_url(confirmation_token: token, host: @store.url)
in full:
Copy code
# frozen_string_literal: true

module Spree
  class UserMailer < BaseMailer
    def reset_password_instructions(user, token, *_args)
      @store = Spree::Store.default
      @edit_password_reset_url = spree.edit_spree_user_password_url(reset_password_token: token, host: @store.url)
      mail to: user.email, from: from_address(@store), subject: "#{@store.name} #{I18n.t(:subject, scope: [:devise, :mailer, :reset_password_instructions])}"
    end

    def confirmation_instructions(user, token, _opts = {})
      @store = Spree::Store.default
      @email = user.email
      @confirmation_url = spree.spree_user_confirmation_url(confirmation_token: token, host: @store.url)
      mail to: @email, from: from_address(@store), subject: "#{@store.name} #{I18n.t(:subject, scope: [:devise, :mailer, :confirmation_instructions])}"
    end
  end
end
w
Thanks. The key is the
@store.url
part, as it’s probably resolving to
nil
. You need to create a store up front and assign a URL to it.
please let me know if this does not solve your issue
s
It's working 😉 thank you very much @waiting_for_dev 🙂
👍 1