RestClient :: ResourceNotFound(找不到404资源):

时间:2013-07-06 12:56:47

标签: ruby-on-rails-3.2 rest-client mailgun

我正在尝试使用RestClient和mailgun发送邮件。

我在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 <me@samples.mailgun.org>",  :to => "sergeyo@profista.com, serobnic@mail.ru",  :subject => "Hello",  :text => "Testing some Mailgun awesomness!"

我使用mailgun创建了帐户,并使用了我帐户中提到的上面的密钥和网址。

当我运行代码时,它会出错:

 RestClient::ResourceNotFound (404 Resource Not Found):

有人能帮助我这里出错吗?

1 个答案:

答案 0 :(得分:4)

您必须将此部分“samples.mailgun.org”更改为您的帐户信息中列出的域,其中包含mailgun子域和自定义域。

假设你有一个名为sandbox0000.mailgun.org的子域名

#i prefer to join the strings

url = "https://api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0@api.mailgun.net/v2/sandbox0000.mailgun.org/messages"

RestClient.post url,  :from => "Excited User <me@samples.mailgun.org>",  :to =>    "sergeyo@profista.com, serobnic@mail.ru",  :subject => "Hello",  :text => "Testing some Mailgun awesomness!"

您的api密钥是mailgun的密码,您不应该公开。

相关问题