Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Postfix for Ruby On Rails to send email

I want to have postfix to send email in my ROR project. As its safer and hax more functionality.

But now I'm quite lost. I installed postfix, got ROR working. But next what should I do?

(I only need to send email, not receive it at the moment)

Should I configure postfix, make it able to send email in comment line first, then integrate it into ROR?

If so, how should I set up the configure file in postfix, and how about settings in rails?

Or do I just need do every setting in rails? If so, what should be the detailed setting?

I'm quite confused. Lots of tutorials either are not working or do not suit my situation.

like image 282
asdjkag Avatar asked Jun 27 '14 04:06

asdjkag


People also ask

How do I use SMTP in Ruby on Rails?

Go to the config folder of your emails project and open environment. rb file and add the following line at the bottom of this file. It tells ActionMailer that you want to use the SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux.

What is Default_url_options?

The default_url_options setting is useful for constructing link URLs in email templates. Usually, the :host , i.e. the fully qualified name of the web server, is needed to be set up with this config option. It has nothing to do with sending emails, it only configures displaying links in the emails.


2 Answers

Example Action Mailer Configuration

An example would be adding the following to your appropriate

config/environments/$RAILS_ENV.rb file:

config.action_mailer.delivery_method = :sendmail
# Defaults to:
# config.action_mailer.sendmail_settings = {
#   location: '/usr/sbin/sendmail',
#   arguments: '-i -t'
# }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_options = {from: '[email protected]'}

More information: http://guides.rubyonrails.org/action_mailer_basics.html

like image 90
Andries Avatar answered Nov 13 '22 07:11

Andries


The one below works for me. Paste the snippet in your config/initializers/mail.rb file:

ActionMailer::Base.sendmail_settings = {
        location: "/usr/sbin/sendmail",
        arguments: '-i -t'
}

ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.default charset: "utf-8"
like image 25
tokhi Avatar answered Nov 13 '22 07:11

tokhi