【发布时间】:2014-07-15 19:37:36
【问题描述】:
我在使用 mandrill API for ruby 时遇到问题,我不确定是否是我缺乏对 ruby/api 的理解,是否 mandrill api 存在问题。
我有这个方法,它使用 mandrill 发送电子邮件,然后我使用从 mandrill.messages.send 返回的 id 进行另一个 api 调用,以再次调用 mandrill 以获取电子邮件标题 message-id,以便我可以将其存储在数据库表。
为什么在日志事件的 cmets 中看到 id 明显存在时,我会收到错误 Mandrill::UnknownMessageError (No message exists with the id '64fba1cce24942dea1ada4f905fd7871'):?
# Sends an email to all users for the account_id on the issue
def send_email
require 'mandrill'
...
mandrill = Mandrill::API.new Mandrill::API_KEY
# Email contents
message = {
:subject => self.name,
:from_name => self.account.subdomain,
:text => self.description,
:to => [{
:email => user.email,
:name => user.name
}],
:text => self.description,
:from_email => "noreply@myapp.com",
:headers => {
'reply-to' => 'update@myapp.com'
}
}
results = mandrill.messages.send message # Send email through mandrill
# Loop through results of sent email
results.each do |result|
logger.debug "result id = #{result['_id']}" # LOGS result id = 64fba1cce24942dea1ada4f905fd7871
logger.debug "result = #{result}" # LOGS result = {"email"=>"tomcaflisch@gmail.com", "status"=>"sent", "_id"=>"64fba1cce24942dea1ada4f905fd7871", "reject_reason"=>nil}
id = result['_id'] # Mandrill's internal id from api call results that sent the email
# CAUSES Mandrill::UnknownMessageError (No message exists with the id '64fba1cce24942dea1ada4f905fd7871'):
info = mandrill.messages.content id # Get info for sent email with a specific mandrill id
end
end
【问题讨论】: