How do i collect the users emails into mandrill ?
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
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