learn-ruby-on-rails教程,mailchimp不发送任何电子邮件

时间:2015-10-30 13:34:35

标签: ruby-on-rails mailchimp learn-ruby-on-rails

我一直在关注本教程,并且已经在heroku上进行了部署。 联系表单完美地工作,并且不显示错误消息。 当我使用注册按钮时,会显示成功消息,但不显示错误消息。在mailchimp上登录显示该电子邮件确实已添加到列表中。

但是,我没有收到任何确认电子邮件(等待24小时并使用2封单独的电子邮件注册),无论是收件人电子邮件还是注册电子邮件。我已在“创建表单”部分检查了“设置/列表名称和默认广告系列/发送最终欢迎电子邮件”框以及“发送最终欢迎电子邮件”框。

我认为问题在于我的mailchimp设置,但我不确定。 我也不确定我们是否打算使用“选择加入电子邮件”或如何激活它。我是mailchimp的新手,整个注册表单系统让我很困惑。请帮忙。

编辑:按要求包含文件:

配置/环境/ development.rb

    Rails.application.configure do
      # Settings specified here will take precedence over those in config/application.rb.

      # In the development environment your application's code is reloaded on
      # every request. This slows down response time but is perfect for development
      # since you don't have to restart the web server when you make code changes.
      config.cache_classes = false

      # Do not eager load code on boot.
      config.eager_load = false

      # Show full error reports and disable caching.
      config.consider_all_requests_local       = true
      config.action_controller.perform_caching = false

      # Don't care if the mailer can't send.
      config.action_mailer.raise_delivery_errors = false

      # Print deprecation notices to the Rails logger.
      config.active_support.deprecation = :log

      # Raise an error on page load if there are pending migrations.
      config.active_record.migration_error = :page_load

      # Debug mode disables concatenation and preprocessing of assets.
      # This option may cause significant delays in view rendering with a large
      # number of complex assets.
      config.assets.debug = true

      config.action_mailer.smtp_settings = {
        address: "smtp.gmail.com",
        port: 587,
        domain: Rails.application.secrets.domain_name,
        authentications: "plain",
        enable_starttls_auto: true,
        user_name: Rails.application.secrets.email_provider_username,
        password: Rails.application.secrets.email_provider_password
      }
      # ActionMailer Config
      config.action_mailer.default_url_options = { :host => 'localhost:3000' }
      config.action_mailer.delivery_method = :smtp
      config.action_mailer.raise_delivery_errors = true
      # Send email in development mode?
      config.action_mailer.perform_deliveries = true

      # Asset digests allow you to set far-future HTTP expiration dates on all assets,
      # yet still be able to expire them through the digest params.
      config.assets.digest = true

      # Adds additional error checking when serving assets at runtime.
      # Checks for improperly declared sprockets dependencies.
      # Raises helpful error messages.
      config.assets.raise_runtime_errors = true

      # Raises error for missing translations
      # config.action_view.raise_on_missing_translations = true
    end

1 个答案:

答案 0 :(得分:0)

好吧,我解决了将状态从“已订阅”更改为“待定”的问题,显然,当使用单一选择时,mailchimp不会发送最终欢迎电子邮件。这会发送一封要求确认的电子邮件,一旦确认,它就会发送最终欢迎电子邮件和给所有者的通知。我不认为这是书中的方法,如果有人以另一种方式解决,请告诉我。

    def subscribe
      mailchimp = Gibbon::Request.new(api_key: Rails.application.secrets.mailchimp_api_key)
      list_id = Rails.application.secrets.mailchimp_list_id
      result = mailchimp.lists(list_id).members.create(
        body: {
          email_address: self.email,
          status: 'pending'
      })
      Rails.logger.info("Subscribed #{self.email} to MailChimp") if result
    end