Mandrill API 使用 send_at 发送预定的电子邮件
Mandrill API sending scheduled emails with send_at
文档不是很清楚如何使用 send_at 参数。我正在使用以下功能发送预定的电子邮件。我尝试了 API 文档要求的不同版本的日期时间。
我所有的电子邮件都立即发送,没有安排。
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
来自 mandrill api 文档:
何时应将此消息作为 YYYY-MM-DD HH:MM:SS 格式的 UTC 时间戳发送。如果您指定过去的时间,消息将立即发送。预定电子邮件需要额外收费,此功能仅适用于余额为正的帐户。
如果我不得不猜测,我会猜测 send_at = time_now
需要变成 send_at = time_now.to_s
才能使 send_at 符合所需的格式。
找到答案,如果要使用预定电子邮件,则必须包含异步和 ip_pool..
async = false
ip_pool = "Main Pool"
send_at = "example send_at"
result = mandrill.messages.send message, async, ip_pool, send_at
文档不是很清楚如何使用 send_at 参数。我正在使用以下功能发送预定的电子邮件。我尝试了 API 文档要求的不同版本的日期时间。
我所有的电子邮件都立即发送,没有安排。
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
来自 mandrill api 文档:
何时应将此消息作为 YYYY-MM-DD HH:MM:SS 格式的 UTC 时间戳发送。如果您指定过去的时间,消息将立即发送。预定电子邮件需要额外收费,此功能仅适用于余额为正的帐户。
如果我不得不猜测,我会猜测 send_at = time_now
需要变成 send_at = time_now.to_s
才能使 send_at 符合所需的格式。
找到答案,如果要使用预定电子邮件,则必须包含异步和 ip_pool..
async = false
ip_pool = "Main Pool"
send_at = "example send_at"
result = mandrill.messages.send message, async, ip_pool, send_at