如何在 Rails 应用程序的 mailgun 消息 api 中检索存储的消息

How to retrieve stored message in mailgun messages api for Rails app

我正在使用 mailgun 将收到的电子邮件转换为我的 rails 应用程序的 post 请求,这部分工作正常,但我也希望能够从 mailgun 检索存储的消息消息 API,但我无法完成。他们的消息 api 的文档是:

https://documentation.mailgun.com/en/latest/api-sending.html#retrieving-stored-messages

为了让事情更简单,我在我的 rails 应用程序中安装了 RestClient gem,并在 rails 控制台中对其进行了修改,但无法将完整的电子邮件对象发送到 return.

编辑 - 我可以使用 Postman 应用程序成功获取存储消息 URL 的请求,使用 'api' 作为用户名和我的 api 密钥作为密码的基本授权。但是当我尝试使用 rest-client gem 发出此请求时,它给了我一个 401 unauthorized 错误。这是我在 rails 应用程序的控制台中进行的尝试。

url = 'https://se.api.mailgun.net/v3/domains/rest-of-the-url...'
user = 'api'
secret ='my-api-key'

RestClient::Request.execute method: :get, url: url, username: user, password: secret

不确定为什么它以前不起作用,但对于任何好奇的人来说,这种使用 rest-client gem 的方法似乎可以解决问题![​​=11=]

url = [url of stored email]
user = 'api'
secret ='my-api-key'

response = RestClient::Request.execute method: :get, url: url, user: user, password: secret
email = JSON.parse(response.body) # the email object!