5

I'm trying to send emails via sendmail in Padrino. I did the configuration specified here (Configuration and Quick Usage)

But I always get the following error in the server log (on Heroku or localhost):

app[web.1]: sh: Illegal option - 
app[web.1]: Errno::EPIPE - Broken pipe:

I installed the mail gem and I'm using Padrino 0.10.7

I'm using this, to send the email:

post :create do
  email(:from => "tony@reyes.com", :to => "john@smith.com", :subject => "Welcome!", :body=>"Body")
end

That's practically all I have...

Luis Ortega Araneda
  • 865
  • 1
  • 12
  • 26
  • What settings are you using? Also, where is that error taking place, in Padrino or some other gem? Need more details about the error. – Arman H Apr 02 '13 at 20:42
  • Settings like what? you mean my Gemfile? The error takes place in my server log. – Luis Ortega Araneda Apr 02 '13 at 21:17
  • Hey @LuisOrtegaAraneda, could you try with Padrino 0.11.0? As for the settings Arman mentions, he might be referring to the delivery_method on the app settings? – Darío Javier Cravero Apr 02 '13 at 21:33
  • What does your `set :delivery_method` look like? Are you sending through SMTP? Your error is reported in your log files, but it's being generated by some part of your program. Can you provide some details from the error log? I don't think `Errno::EPIPE` is related to your mailer code; something else is breaking. – Arman H Apr 02 '13 at 23:08
  • Are you trying to run this locally or on heroku? If you are running it locally then it might be having difficulty connecting with padrino. I know heroku introduces some configuration etc on the fly when a deploy is made and the server is started, for example it automatically switches your database settings to use their addon's postgres. – whizcreed Apr 03 '13 at 12:50

2 Answers2

5

You should be using one of the parter addons for sending mail with Heroku.

A good option is Sendgrid

heroku addons:add sendgrid:starter --app=your_app_name

Then in your Padrino app in app.rb inside your App class:

set :delivery_method, :smtp => { 
  :address              => "smtp.sendgrid.net",
  :port                 => 587,
  :domain               => 'heroku.com',
  :user_name            => ENV['SENDGRID_USERNAME'],
  :password             => ENV['SENDGRID_PASSWORD'],
  :authentication       => :plain,
  :enable_starttls_auto => true  
}

You could substitute these for settings for another external SMTP server, or look at Mandrill for transactional emails.

I suspect the Errno::EPIPE error you were seeing was that it could not connect to a valid SMTP server, so your controller code should be fine as it is.

stef
  • 14,172
  • 2
  • 48
  • 70
  • AFAIK (been a while since last time i configured mail sending in heroku) you dont have to use any heroku addon for it. Not even [Heroku help](https://devcenter.heroku.com/articles/smtp) says it. – trompa Apr 05 '13 at 07:49
  • @Trompa: you don't need an add-on, but you do need an SMTP server to send emails through (as Heroku doesn't provide one). – pat Apr 07 '13 at 08:22
0

Pat is right, you don't need an add-on, just configure your app.rb like stef suggests and you're good to go. So, for example, we use gmail and our config looks something like this:

  set :delivery_method, :smtp => {
    :address              => "smtp.domain.com",
    :port                 => 587,
    :domain               => 'rails.domain.com',
    :user_name            => "rails@domain.com",
    :password             => "super-secret",
    :authentication       => "plain",
    :enable_starttls_auto => true,
    :openssl_verify_mode  => OpenSSL::SSL::VERIFY_NONE
  }
kakubei
  • 5,321
  • 4
  • 44
  • 66