Mandrill API使用send_at发送计划的电子邮件 [英] Mandrill API sending scheduled emails with send_at
本文介绍了Mandrill API使用send_at发送计划的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
文档尚不清楚如何使用send_at参数。我正在使用以下功能发送预定的电子邮件。我尝试了API文档要求的不同日期时间版本。
The documentation isn't very clear how to use the send_at parameter. I am sending a scheduled email using the function below. I have tried different versions of the datetime required by the API documentation.
我的所有电子邮件都已立即发送,而不是按计划发送。
All my emails are being send right away and not scheduled.
def send_member_email_batch(current_user, recipient_emails, recipient_names, subject, body, scheduled)
m = Mandrill::API.new ENV["MANDRILL_APIKEY"]
recipient_emails.each_with_index do |recipient, index|
to_address = (recipient_emails.length > 1) ? [{"email"=>recipient,"name"=>recipient_names[index], "type"=>"to"}] :
[{"email"=>recipient,
"name"=>recipient_names[index],
"type"=>"to"},
{"email"=>current_user.email,
"name"=>current_user.name,
"type"=>"cc"}]
message = {
:from_name=> current_user.name,
:from_email=> current_user.email,
:to=> to_address,
:subject=> temp_subject,
:html=> temp_body,
:auto_text=>true,
:tags=> ["members"],
:track_opens=>true,
:track_clicks=>true,
:preserve_recipients => false
}
time_now = DateTime.now.utc
time_now += (1 + ((5-time_now.wday) % 7))
time_now = time_now.change({hour: 12, min: 3, sec: 0 }).strftime('%F %T')
puts time_now #2015-10-10 12:03:00
send_at = time_now
#puts "to: #{recipient}, subject = #{temp_subject}, message = #{temp_body}"
begin
result = m.messages.send message, send_at
puts result #email is not scheduled
rescue Mandrill::Error => e
puts "A mandrill error occurred: #{e.class} - #{e.message}"
next
end
end
end
https://mandrillapp.com/api/docs/messages.ruby.html#method=send
推荐答案
找到答案,如果要使用计划的电子邮件,则必须包括async和ip_pool。
Found the answer, you have to include async and ip_pool if you want to use scheduled emails..
async = false
ip_pool = "Main Pool"
send_at = "example send_at"
result = mandrill.messages.send message, async, ip_pool, send_at
这篇关于Mandrill API使用send_at发送计划的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文