Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestClient::ResourceNotFound (404 Resource Not Found):

I am trying to send mails using RestClient and mailgun.

I installed gem in my rails app and defined "require 'rest_client'" in config/application.rb.

Then to send mail, I wrote this in my message controller:

 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!"

I have created account with mailgun and used keys and url above as mentioned in my account.

When I run code, it gives error:

 RestClient::ResourceNotFound (404 Resource Not Found):

Can anybody help me whats going wrong here?

like image 801
user2206724 Avatar asked Oct 04 '22 15:10

user2206724


1 Answers

You have to change this part "samples.mailgun.org" to a domain listed in your account info, there are mailgun subdomains and custom domains.

Assuming yo have a subdomain named 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!"

Your api key is a password to mailgun and you should not make it public.

like image 198
Erick Eduardo Garcia Avatar answered Oct 11 '22 14:10

Erick Eduardo Garcia