Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send emails with Padrino in Heroku

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 => "[email protected]", :to => "[email protected]", :subject => "Welcome!", :body=>"Body")
end

That's practically all I have...

like image 346
Luis Ortega Araneda Avatar asked Mar 22 '13 13:03

Luis Ortega Araneda


1 Answers

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.

like image 171
stef Avatar answered Sep 27 '22 20:09

stef