2012-11-28 203 views
0

我想通過mailchimp發送電子郵件通知。通過mailchimp api發送通知郵件

我讀的doc和我寫了一些代碼,所以我用api.lists獲取列表:

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) 
$LOAD_PATH.unshift(File.dirname(__FILE__)) 
require 'mailchimp' 
@options = ["list_id" => "$list_id", "subject" => "test subject", "from_name" => "test name", "from_email" => "[email protected]"] 
@content = ["html" => "<p> test content </p>"] 
@type = 'regular' 
@title = 'Test Newsletter Title'   
api = Mailchimp::API.new("key") 
puts "Your lists:" 
api.lists['data'].each do |list| 
    puts "\t #{list['name']}" 
end 

campaignCreate: 我創建了一個活動是這樣的:

api.campaignCreate(@type, @title, @content) 

當我通過使用上面創建一個廣告系列,然後我得到以下錯誤:wrong number of arguments (4 for 2)

我想發送通知郵件。我怎樣才能做到這一點?

回答

0

我做到了,用這個

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) 
$LOAD_PATH.unshift(File.dirname(__FILE__)) 
require 'mailchimp' 
api = Mailchimp::API.new("api-key") 
@content = {"html"=>"<p> test content </p>","text"=> "test"} 
api.lists['data'].each do |list| 
    @options = {"list_id"=> list['id'], "subject"=>"test subject", "from_name"=>"test name", "from_email"=>"[email protected]", "template_id" => "xxxx"} 
    campaign = api.campaignCreate({"type"=>"regular", "options" => @options, "content"=> @content}) 
    api.campaignSendNow({"cid" => campaign}) 
end