Sending Email through Mailgun API in Rails

Add gem to Gemfile.

gem 'mailgun-ruby', '~>1.1.6'

Define mail gun api key in the secrets.yml:

  secret_key_base: d8fc3a9ced2de8ed70
  mail_gun_api_key: key-123456

In the rails console:

client =
email =  { from: '',
           to:   '',
           subject: 'The Ruby SDK is awesome!',
           text:    'It is really easy to send a message!'
client.send_message '', email
Mailgun::CommunicationError (Permission bits for '/Users/bparanj/.netrc' should be 0600, but are 644)

This fails to send email in development environment. Change the permissions on the .netrc file.

$ ll ~/.netrc
-rw-r--r--  1 bparanj  staff  70 May 21  2017 /Users/bparanj/.netrc
$ chmod 600 $HOME/.netrc
$ ll ~/.netrc
-rw-------  1 bparanj  staff  70 May 21  2017 /Users/bparanj/.netrc

Permission problem is resolved. The new problem is that my domain does not have anything hosted. The new error is:

Mailgun::CommunicationError (404 Not Found: Domain not found:

Related Articles

Create your own user feedback survey