【问题标题】:Mandrill - No message exists with idMandrill - 不存在带有 id 的消息
【发布时间】: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

【问题讨论】:

    标签: ruby mandrill


    【解决方案1】:

    我在 messages.info(id) 上遇到同样的错误。

    但是,search('*') 正在查找所有已发送但未提供正确状态信息的消息。

    我认为当调用 messages.info(id) 时,gem 代码的以下 sn-p 状态为 500(而不是 200):

        def call(url, params={})
            params[:key] = @apikey
            params = JSON.generate(params)
            r = @session.post(:path => "#{@path}#{url}.json", :headers => {'Content-Type' => 'application/json'}, :body => params)
    
            cast_error(r.body) if r.status != 200
            return JSON.parse(r.body)
        end
    

    此外,gem 代码托管在 bitbucket 上,而不是更常见的 github 上。不知道如何在那里提出问题以获得支持。

    很抱歉帮不上什么忙,但我想我也应该分享一下我的经验,以便更清楚地了解问题。

    【讨论】:

      【解决方案2】:

      我认为你只需要给它一点时间。

      【讨论】:

      • 仅基于几个测试,确实似乎在几分钟后,结果按预期返回,而不是说“不存在消息”。奇怪的行为。
      猜你喜欢
      • 2023-03-20
      • 2015-08-28
      • 2015-09-09
      • 2015-09-21
      • 2015-08-11
      • 2018-03-24
      • 2016-10-14
      • 1970-01-01
      • 2018-02-28
      相关资源
      最近更新 更多