酷徒LOGO
0 0 评论
文章标签:文件  Mailchimp  上传  Subscribe  CSV  Subscriber  mail  

是否曾经想过将用户批量上传到你的mailchimp帐户,但是由于杂乱无章的警报而受阻? 加上一些神奇的ruby代码和一个API密钥,就可以解决问题 : )

首先,在命令行中输入它;

gem install mailchimp-api
接下来 查找邮件列表的id, 然后生成一个API密钥

require 'mailchimp'
require 'csv

subscribers = []
contents = CSV.parse(File.read('path/to/file.csv', headers: true, header_converters: :symbol))
contents.each_with_index do |row, i|
 # next if i == 0
 mail = row[:email]
 first = row[:first_name]
 if first.nil?
 subscriber = { 'EMAIL' => { 'email' => mail } }
 p "added #{mail} without name"
 else
 p "added #{mail} with #{first}"
 subscriber = { 'EMAIL' => { 'email' => mail },
 :EMAIL_TYPE => 'html',
 :merge_vars => { 'FNAME' => first.capitalize } }
 end
 subscribers << subscriber
end

mailchimp = Mailchimp::API.new('xxxxxxxxxxxx-YOUR-API-KEY-xxxxxxxxxxxxxx')
mailchimp.lists.batch_subscribe('YOUR-LIST-ID', subscribers, false, true, false)


文章标签:文件  上传  mail  CSV  Mailchimp  Subscribe  Subscriber  

Copyright © 2011 HelpLib All rights reserved.    知识分享协议 京ICP备17041772号-2  |  如果智培  |  酷兔英语  |  帮酷