Matrix
Matrix

Reputation: 3369

how send mail with localhost using rails 4?

I search the equivalent to very simple PHP mail function, in ruby.

I watch http://guides.rubyonrails.org/action_mailer_basics.html and I trid to use it but it's not clear.

The only exemple I found on guide and on others responses on SO it's about "gmail smtp". I don't want used gmail smtp, just local smtp server to test mail function like on WAMP.

I tried :sendmail delivery_method, but it respond "/bin/sendmail doesn't exist", so I install postfix in local and add this config to development.rb :

  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.delivery_method = :sendmail
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true  

log of my rails server :

UserMailer#welcome_email: processed outbound mail in 2.4ms

Sent mail to [email protected] (59.5ms) Date: Wed, 10 Dec 2014 12:08:02 +0100 From: [email protected] To: mytruedomain.com Message-ID: <[email protected]> Subject: test Mime-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit

un test

but I never recieve it in my mail box at [email protected]...

EDIT: when I watch log of postfix :

postfix/error[6335]: 7ECBD5C29E5: to=, relay=none, delay=0.14, delays=0.08/0/0/0.06, dsn=5.0.0, status=bounced (mytruedomain.com)

What specific config is missing/needed with my local postfix?

So how can I do to send mail? I just want send mail, I don't understand how it's so complicated !

Upvotes: 2

Views: 4968

Answers (2)

kurenn
kurenn

Reputation: 1055

Try the code from Paulo Fidalgo, and I'll recommend you use mailcatcher.

Actually you just need this line in your development.rb file:

config.action_mailer.delivery_method = :smtp

Upvotes: 0

Paulo Fidalgo
Paulo Fidalgo

Reputation: 22296

First test if your server is working:

date | mail -s test [email protected]

Then configure your application to send the email using smtp:

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address => "localhost",
  :port => 25,
  :domain => "domain.com",
}

Upvotes: 3

Related Questions