5

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 <me@samples.mailgun.org>",  :to => "sergeyo@profista.com, serobnic@mail.ru",  :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?

user2206724
  • 1,265
  • 3
  • 20
  • 38

1 Answers1

4

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

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

Erick Eduardo Garcia
  • 1,147
  • 13
  • 17