Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do i collect the users emails into mandrill ?

Ahmed Althani asked in Gems / Libraries

I have watched the mandrill tutorial. I just have a quick question. How can i link the list on mandrill or any email service with the users emails (when the user signs up ) and update the list whenever someone signs up ? Thanks

Reply

Hey Ahmed,

Sorry for the slow reply on this one. You can add an after_create callback to your User model to add the email to the mailing list via their API. If you're using Mailchimp, you can use the Gibbon gem to do that.

I do something like this for GoRails when someone subscribes:

class User
    def add_to_mailchimp
    $gibbon.lists.subscribe(
      id: "a04070a071",
      email: {email: email},
      double_optin: false,
      merge_vars: {
        FNAME: first_name,
        LNAME: last_name,
        PLAN: (subscribed? ? "screencast-9" : ""),
      }
    ) if Rails.env.production?
  rescue Gibbon::MailChimpError => e
    Rails.logger.error "Unable to add #{email} to mailchimp: #{e}"
  end
end
# config/initializers/gibbon.rb
$gibbon = Gibbon::API.new Rails.application.secrets.mailchimp_api_key
# config/secrets.yml
production:
  mailchimp_api_key: MY_API_KEY
Reply

Thanks for your help Chris :) !!!

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.