2017-08-10 28 views
1

我正在使用mailgun將傳入的電子郵件轉換爲發佈我的rails應用的請求,並且該部分工作正常,但我也希望能夠檢索存儲的郵件mailgun郵件API,並且遇到了麻煩。對於他們的消息API的文檔是:如何檢索mailgun郵件api中存儲的郵件Rails應用

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

爲了方便起見我安裝在我的Rails應用程序的RESTClient實現的寶石,並用它在軌控制檯周圍黑客攻擊,但不能得到完整的電子郵件對象返回。

編輯 - 我可以使用Postman應用程序對存儲的郵件URL進行成功的獲取請求,使用用戶名和'api'密碼的基本授權。但是,當我嘗試使用其餘客戶端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 
+0

喂...包括這個問題的一個更好的解釋,並指出我們不工作的代碼,或者你不明白 –

+0

編輯的問題,以增加更多的細節,包括我製作一個GET請求代碼 – TDB

回答

0

不知道爲什麼它以前不工作,但對於任何好奇的人來說,這種使用rest-client gem的方法似乎有訣竅!

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! 
相關問題