How to Send Email in Development with Spree

后端 未结 4 1461
抹茶落季
抹茶落季 2020-12-19 18:57

I\'m in the development environment and I want to send out test emails via my console. I got the console going nice, but its not sending.

I go to Spree\'s Mail Metho

相关标签:
4条回答
  • 2020-12-19 19:43

    The problem is that you need a local email server that can receive your emails. To test the setup in development install the mailcatcher gem, that you will use as a SMTP server in development, catching all incoming mails and displaying them on http://localhost:1080/:

    Just run in the terminal

    gem install mailcatcher

    then run mailcatcher in the console. A toy SMTP server will be running on port 1025 catching emails and displaing them on HTTP port 1080.

    Then just goto the spree admin panel and configure it. The following settings work perfectly for me without any code writing.

    enter image description here

    After I clicked on send test mail I got the following email on my localhost:

    enter image description here

    0 讨论(0)
  • 2020-12-19 19:48

    Spree commerce use ActionMailer to send emails. If you want send emails in development mode, you should enable delivery_method in config/enviranments/development.rb file.

    Just set this variable config.action_mailer.delivery_method = :smtp

    0 讨论(0)
  • 2020-12-19 19:49

    This problem arises because you don’t have a local email server to receive your emails.

    Step 1: The first step would be to Install the mailcatcher gem in order to test the setup in development.

    You will be using it as a SMTP server to catch all the incoming mails and display them on http://localhost:1080/:

    Step 2: Just run in the terminal “gem install mailcatcher” in the console.

    You will find an SMTP server running on port 1025 catching emails and displaying them on HTTP port 1080

    Step 3: You will find an SMTP server running on port 1025 catching emails and displaying them on HTTP port 1080

    Add line: gem 'spree_mail_settings', github: 'spree-contrib/spree_mail_settings', branch: 'master‘

    Then run: bundle

    Step 4: Further, go to “Spree admin panel” and configure it. These settings will work perfectly for you without any code writing.

    Then click on “Send test mail

    Step 5:

    You will receive the an email on your local host.

    Now your problem is solved.

    0 讨论(0)
  • 2020-12-19 19:50

    Spree actually overrides the ActionMailer settings with the settings input in the graphical interface using the Spree::MailMethod class. On the plus side, you can set things in the admin interface, with a downside of several unexpected behaviours.

    We maintain many Spree stores and we always run with the settings:

    Spree.config do |config|
      config.override_actionmailer_config = false
      config.mails_from = "no-reply@yourdomain.com"
    end
    

    This will allow you to configure ActionMailer as you would in any other Rails application: http://guides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration

    This is being adopted as standard procedure for the next release of Spree after 2.2.x.

    https://github.com/spree/spree/pull/4377 has extracted the web configuration to its own gem to maintain backwards compatibility.

    0 讨论(0)
提交回复
热议问题