How to configure sending email through localhost application server without authentication?

I set up the Rails mailer in config / initializers / like the following:

/config/initializers/setup_email.rb

config.action_mailer.raise_delivery_errors = true ActionMailer::Base.smtp_settings = { :address => "smtp.gmail.com", :port => 587, :domain => 'gmail.com', :authentication => :plain, :user_name=><username>, :password=><password>, :enable_starttls_auto => true } 

It works great, I can send emails and receive them.

But how to configure it to send emails with localhost without authentication (without username and password) that do not use gmail but send emails through the local application server, how to configure?

- EDIT --- When using localhost, I received an error message:

 Connection refused - connect(2) /home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/net/smtp.rb:551:in `initialize' /home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/net/smtp.rb:551:in `open' /home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/net/smtp.rb:551:in `do_start' /home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/timeout.rb:67:in `timeout' /home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/timeout.rb:101:in `timeout' /home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/net/smtp.rb:551:in `do_start' /home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/net/smtp.rb:525:in `start' /home/user1/.rvm/gems/ ruby-1.8.7-p330@myapp /gems/mail-2.2.15/lib/mail/network/delivery_methods/smtp.rb:127:in `deliver!' /home/user1/.rvm/gems/ ruby-1.8.7-p330@myapp /gems/mail-2.2.15/lib/mail/message.rb:1967:in `do_delivery' /home/user1/.rvm/gems/ ruby-1.8.7-p330@myapp /gems/mail-2.2.15/lib/mail/message.rb:228:in `deliver' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/actionmailer-3.0.3/lib/action_mailer/base.rb:401:in `deliver_mail' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/activesupport-3.0.3/lib/active_support/messages.rb:52:in `instrument' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/activesupport-3.0.3/lib/active_support/messages/instrumenter.rb:21:in `instrument' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/activesupport-3.0.3/lib/active_support/messages.rb:52:in `instrument' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/actionmailer-3.0.3/lib/action_mailer/base.rb:399:in `deliver_mail' /home/user1/.rvm/gems/ ruby-1.8.7-p330@myapp /gems/mail-2.2.15/lib/mail/message.rb:228:in `deliver' /home/user1/myapp/app/mailers/my_mailer.rb:9:in `new_car_messages' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/actionpack-3.0.3/lib/abstract_controller/base.rb:151:in `send_action' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/actionpack-3.0.3/lib/abstract_controller/base.rb:151:in `process_action' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/actionpack-3.0.3/lib/abstract_controller/base.rb:120:in `process' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/actionpack-3.0.3/lib/abstract_controller/rendering.rb:40:in `process' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/actionmailer-3.0.3/lib/action_mailer/old_api.rb:75:in `process' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/actionmailer-3.0.3/lib/action_mailer/base.rb:446:in `process' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/actionmailer-3.0.3/lib/action_mailer/base.rb:441:in `initialize' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/actionmailer-3.0.3/lib/action_mailer/base.rb:425:in `new' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/actionmailer-3.0.3/lib/action_mailer/base.rb:425:in `method_missing' /home/user1/myapp/config/../lib/my/new_car_sender.rb:7:in `send_email' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/activerecord-3.0.3/lib/active_record/relation.rb:13:in `each' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/activerecord-3.0.3/lib/active_record/relation.rb:13:in `__send__' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/activerecord-3.0.3/lib/active_record/relation.rb:13:in `each' /home/user1/myapp/config/../lib/my/new_car_sender.rb:6:in `send_email' /home/user1/myapp/lib/tasks/new_car_messages.rake:8 /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:636:in `call' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:636:in `execute' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:631:in `each' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:631:in `execute' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain' /home/user1/.rvm/rubies/ruby-1.8.7-p330/lib/ruby/1.8/monitor.rb:242:in `synchronize' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:583:in `invoke' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:2029:in `each' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:2029:in `top_level' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:2023:in `top_level' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:2001:in `run' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/lib/rake.rb:1998:in `run' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /gems/rake-0.8.7/bin/rake:31 /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /bin/rake:19:in `load' /home/user1/.rvm/gems/ ruby-1.8.7-p330@global /bin/rake:19 
+6
ruby-on-rails ruby-on-rails-3 actionmailer
source share
7 answers

If you have configured a local SMTP server, you should simply provide connection information for this:

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

You should have this in config / environment / * files. rb.

+4
source share

To send letters you need to configure the SMTP server. You can configure it locally or use a remote service such as Gmail, SendGrid or Mandrill. In your case, I would suggest using mailcatcher .

From the docs:

how

  • gem install mailcatcher
  • mailcatcher
  • Go to http://localhost:1080/
  • Send mail via smtp://localhost:1025

Rails

To configure the rails application, I recommend adding it to your /development.rb environment:

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

+3
source share

If you are checking email functionality with localhost, first find out if sendmail is installed and working if it does not run this command in the terminal:

sudo apt-get install sendmail

after installing this attempt to send an email .. because the configuration looks ok ..

+2
source share

Add the letter_opener gem to the development gem group in the Gemfile .

Add these lines to development.rb :

 config.action_mailer.delivery_method = :letter_opener config.action_mailer.default_url_options = { host: "localhost, port: 3000" } 

and you should see that running emails appear in your browser without starting the STMP server and authentication.

Email in Chrome: enter image description here

+2
source share

enable_starttls_auto: false option added to solve the problem.

Here is my configuration (.. \ config \ environment \ development.rb):

 config.action_mailer.perform_deliveries = true config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'localhost', port: 25, domain: 'exmaple.com', enable_starttls_auto: false } 

 ruby 2.2.3p173 (2015-08-18 revision 51636) [x64-mingw32] Rails 4.2.5` 
+1
source share

And even shorter: No entry at all. Both localhost and the default port number.

My current configuration in config / development.rb:

 #config.action_mailer.default_url_options = { :host => 'localhost' } 

I continued to comment to remember where to change when I play with the remote smtp host.

EDIT (since I don't have enough reputation to comment on the correct post): I saw your comment on the @HakonB post that you received "Connection reject - connect (2)". Do you have access to the mail server log on localhost? I think you should take a look at how to solve this problem.

0
source share

Well, you can:

 sudo apt-get install sendmail 

and then change the configuration to:

 ActionMailer::Base.delivery_method = :sendmail 

Finally, you will find that most mail services block your host (a policy to avoid spam).

0
source share

All Articles