简体   繁体   中英

learn-ruby-on-rails tutorial, mailchimp not sending any emails

I've been following the tutorial and have already reach deployment on heroku. The contact forms work perfectly and no errors messages are displaying. When I use the sign up button the success message appears with no error messages. Signing in at mailchimp reveals the email has indeed been added to the list.

However, I am not receiving any confirmation emails(waited 24 hours and signing up with 2 separate emails), either to owner email or the signup email. I have checked the "settings/list name and default campaigns/send a final welcome email" box as well as the "send a final welcome email" box at the create forms section.

I believe the issue is with my mailchimp settings somewhere but I'm not sure. I'm also not sure if we're meant to be using an "opt in email" or how to activate this. I'm new to mailchimp and the whole signup forms system is confusing to me. Please help.

EDIT: file included as requested:

config/environments/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

Well I solved the problem changing status from "subscribed" to "pending", apparently mailchimp doesn't send final welcome emails when it uses single opt in. This sends out an email asking for confirmation and once confirmed then it sends the final welcome email and a notification to the owner. I don't think this was the approach in the book and if anyone solved this another way please let me know.

    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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM