2013-07-06 146 views
5

我想用RestClient和mailgun發送郵件。RestClient :: ResourceNotFound(404資源未找到):

我在我的rails應用程序中安裝了gem,並在config/application.rb中定義了「require'rest_client'」。

然後發送郵件,我在消息控制器寫了這個:

RestClient.post "https://api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0" "@api.mailgun.net/v2/samples.mailgun.org/messages", :from => "Excited User <[email protected]>", :to => "[email protected], [email protected]", :subject => "Hello", :text => "Testing some Mailgun awesomness!" 

我創建帳戶mailgun和使用的密鑰和網址,做爲我的賬戶上面提到。

當我運行的代碼,它提供了錯誤:

RestClient::ResourceNotFound (404 Resource Not Found): 

任何人可以幫助我怎麼回事錯在這裏?

回答

4

您必須將此部分「samples.mailgun.org」更改爲您的帳戶信息中列出的域,這裏有mailgun子域名和自定義域名。

假設喲有一個子域命名sandbox0000.mailgun.org

#i prefer to join the strings 

url = "https://api:[email protected]/v2/sandbox0000.mailgun.org/messages" 

RestClient.post url, :from => "Excited User <[email protected]>", :to => "[email protected], [email protected]", :subject => "Hello", :text => "Testing some Mailgun awesomness!" 

你的API密鑰是mailgun一個密碼,你不應該把它公開。