Search code examples
rubyherokupadrinomailing

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...


Solution

  • 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.