0

I am deploying a ruby app on AWS using sinatra. I want to use Mandrill to send emails.

I have created a file .ebextensions/app.config and the content is:

option_settings:
  - option_name: MANDRILL_APIKEY
    value: api_key_password
  - option_name: MANDRILL_USERNAME
    value: api_key_username

Is the structure correct in: .ebextensions/app.config

and is the file correct?

Either way it does not work and the error is "Wrong number of argumaents 0 (for 1..2)" so presumably nothing is being passed.

The email code snippet is:

require 'mandrill'

m = Mandrill::API.new
message = {  
 :subject=> "Hello from the Mandrill API",  
 :from_name=> "Cloudflow",  
 :text=>"Hi message, how are you?",  
 :to=>[  
   {  
     :email=> "user@gmail.com",  
     :name=> "User"  
   }  
 ],  
 :html=>"<html><h1>Hi <strong>message</strong>, how are you?</h1></html>",  
 :from_email=>"notification@cloudflow.sh"  
}  
sending = m.messages.send message  
puts sending

All help appreciated chaps, thank you.

user1903663
  • 1,713
  • 2
  • 22
  • 44
  • Please provide the stacktrace for the error. – Satya Jan 19 '15 at 16:36
  • https://elasticbeanstalk-us-east-1-354654731898.s3.amazonaws.com/resources/environments/logs/tail/e-6m2emci3ce/i-6097998c/TailLogs-1421687442101.out?AWSAccessKeyId=AKIAIOUOORMVUTXOJUHQ&Expires=1421773843&Signature=eKlMq5FKhD07xXYxxNk%2BYp7CDPE%3D full trace here – user1903663 Jan 19 '15 at 17:17
  • I get permission denied for that. – Satya Jan 20 '15 at 14:03
  • yes, sorry, the logs automatically "self destruct". Anyway, all good now pls see below. Also, thanks for the link - very useful. I appreciate it. – user1903663 Jan 20 '15 at 16:50

1 Answers1

0

You need to pass your api key to the 'new' method on Mandrill::API.

You'll need to read the aws config file first, I presume.

m = Mandrill::API.new api_key_here

More info: https://mandrillapp.com/api/docs/index.ruby.html

Satya
  • 4,458
  • 21
  • 29
  • thanks, it is not necessary to write the api_key there. Mandrill expects to find them in the ENV not written in to the code. The point is that I believe the error is occurring in app.config file or the structure of the folders and not in the mandrill code snippet which has worked correctly, as is, on heroku with the credentials stored in the ENV. – user1903663 Jan 19 '15 at 16:14
  • === puma startup: 2015-01-19 17:08:30 +0000 === === puma startup: 2015-01-19 17:08:30 +0000 === [18010] + Gemfile in context: /var/app/current/Gemfile [18007] - Worker 0 (pid: 18010) booted, phase: 0 ArgumentError - wrong number of arguments (0 for 1..2): /opt/rubies/ruby-2.1.4/lib/ruby/gems/2.1.0/gems/mandrill-0.0.4/lib/mandrill/api.rb:35:in `initialize' /var/app/current/app.rb:25:in `new' /var/app/current/app.rb:25:in `block in ' – user1903663 Jan 19 '15 at 17:13
  • it's just not reading from the app.config file, I think. Thank you for your time. – user1903663 Jan 19 '15 at 17:14
  • http://stackoverflow.com/questions/11211007/how-do-you-pass-custom-environment-variable-on-amazon-elastic-beanstalk-aws-ebs This might help. Reading the mandrill API docs, I still say you need to pass the key to the `new` method. – Satya Jan 20 '15 at 14:03
  • thanks, appreciate your comments.I have read the Mandrill docs and I can assure you that there is nothing wrong with the Mandrill code. It now, in fact works, as above (without adding the api_key as you suggested and it is a mistake to do so). The mistake, as I felt was the case, lay in the placing of the app.config file in the right directory. Otherwise everything else is correct. Sorry to waste your time. – user1903663 Jan 20 '15 at 16:43
  • check this out: http://help.mandrill.com/entries/23257181-Using-the-Mandrill-Ruby-Gem Mandrill expects to find the credentials in the ENV. Anyway, once again thank you for your time. – user1903663 Jan 20 '15 at 17:08
  • The best part is, I use that gem exactly like that: with the MANDRILL_APIKEY in the ENV (on Heroku, not on AWS). I was going by the docs at the link in my answer, which do pass arguments to the `new` method. Not sure what that's about, now. I suggest you put the correct location of the `app.config` file as a separate answer to your own question, and set it as 'accepted'. – Satya Jan 21 '15 at 04:27