Hi,
MailChimp provides Free email marketing service. You can simply design your email template with nice tools provided by mailchimp and can easily send to list of members that were maintained in the mailchimp list directory.
MailChimp provides many features, For now I am just concentrating on the creating user record in the MailChimp List.
Inorder to Implement mailChimp in ruby on rails application, we have nice gem hominid(https://github.com/terra-firma/hominid). Hominid provides required methods to connect to MailChimp api.
Lets start by creating an account in mailchimp by registering as a free user. Once you logged in to MailChimp You can get the required api access details from the 'API Keys & Authorized Apps' section under the 'Account' tab. You can get api key from that section.
--------------------------
Add the gem to your gem file.
> gem "hominid"
---------------------------
Configure the mailchimp credentails(api) details in yml file under config/mail_chimp.yml
common: &default_settings
api_key: "asfgtc4a6cd9917tyuhb752867c23eb5-er5"
subscriber_list: "g67b678706"
development:
<<: *default_settings
test:
<<: *default_settings
demo:
<<: *default_settings
staging:
<<: *default_settings
production:
api_key: "xxxxxxxxxxxxxxxxxxxxxxx"
subscriber_list: "xxxxxxxxxx"
------------------------------
Load the configuratiosn in initializer file in config/initializers/mail_chimp.rb
MAIL_CHIMP = YAML.load_file("#{Rails.root}/config/mail_chimp.yml")
--------------------------------
Craete a class with Mailchimp under model folder models/mail_chimp.rb
class MailChimp
include Hominid
def self.add_user(user)
h = Hominid::API.new(MAIL_CHIMP[Rails.env]['api_key'])
h.list_subscribe(MAIL_CHIMP[Rails.env]['subscriber_list'], user.email, {'FNAME' => user.first_name, 'LNAME' => user.last_name}, 'html', false, true, true, false)
end
def self.unsubscribe_user(user)
h = Hominid::API.new(MAIL_CHIMP[Rails.env]['api_key'])
h.list_unsubscribe(MAIL_CHIMP[Rails.env]['subscriber_list'], user.email)
end
end
------------------------------
You need to call the above methods in your user class after creating the user by using call back 'after_create' in models/user.rb
after_create :create_user_record_in_mailchimp
def create_user_record_in_mailchimp
MailChimp.add_user(self)
end
----------------------------------
The above explanation helps you to create user record in mailchimp list while user creates in the rails application.
Thank You,
Uma Mahesh.
MailChimp provides Free email marketing service. You can simply design your email template with nice tools provided by mailchimp and can easily send to list of members that were maintained in the mailchimp list directory.
MailChimp provides many features, For now I am just concentrating on the creating user record in the MailChimp List.
Inorder to Implement mailChimp in ruby on rails application, we have nice gem hominid(https://github.com/terra-firma/hominid). Hominid provides required methods to connect to MailChimp api.
Lets start by creating an account in mailchimp by registering as a free user. Once you logged in to MailChimp You can get the required api access details from the 'API Keys & Authorized Apps' section under the 'Account' tab. You can get api key from that section.
--------------------------
Add the gem to your gem file.
> gem "hominid"
---------------------------
Configure the mailchimp credentails(api) details in yml file under config/mail_chimp.yml
common: &default_settings
api_key: "asfgtc4a6cd9917tyuhb752867c23eb5-er5"
subscriber_list: "g67b678706"
development:
<<: *default_settings
test:
<<: *default_settings
demo:
<<: *default_settings
staging:
<<: *default_settings
production:
api_key: "xxxxxxxxxxxxxxxxxxxxxxx"
subscriber_list: "xxxxxxxxxx"
------------------------------
Load the configuratiosn in initializer file in config/initializers/mail_chimp.rb
MAIL_CHIMP = YAML.load_file("#{Rails.root}/config/mail_chimp.yml")
--------------------------------
Craete a class with Mailchimp under model folder models/mail_chimp.rb
class MailChimp
include Hominid
def self.add_user(user)
h = Hominid::API.new(MAIL_CHIMP[Rails.env]['api_key'])
h.list_subscribe(MAIL_CHIMP[Rails.env]['subscriber_list'], user.email, {'FNAME' => user.first_name, 'LNAME' => user.last_name}, 'html', false, true, true, false)
end
def self.unsubscribe_user(user)
h = Hominid::API.new(MAIL_CHIMP[Rails.env]['api_key'])
h.list_unsubscribe(MAIL_CHIMP[Rails.env]['subscriber_list'], user.email)
end
end
------------------------------
You need to call the above methods in your user class after creating the user by using call back 'after_create' in models/user.rb
after_create :create_user_record_in_mailchimp
def create_user_record_in_mailchimp
MailChimp.add_user(self)
end
----------------------------------
The above explanation helps you to create user record in mailchimp list while user creates in the rails application.
Thank You,
Uma Mahesh.
No comments:
Post a Comment