Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure to send email through localhost app server without authentication?

I have configured the Rails mailer under config/initializers/ like 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 fine, I can send emails and get them received.

But how to configure it to send email from localhost without authentication(without username and password), that's do not use gmail, but send email through the application's local server, how to configure then?

--EDIT--- When using localhost, the error message I got is:

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
like image 970
Mellon Avatar asked Mar 15 '11 08:03

Mellon


People also ask

Can I use SMTP without authentication?

You can't use gmail smtp-server without authentication. It's a google policy. You need to enter your account password.

Can I send email using localhost?

If you want to send emails from localhost directly, you need to install a Mail Transport Agent (MTA), or if you like, a SMTP service. IIS provides one. You can otherwise find some others on Google.

How do I send an email with NodeMailer without authentication?

Use NodeMailer. This will give you two options: You can remove auth from the example code when creating a SMTP Transport message if you have local IIS SMTP turned on. Obviously, set host: 'localhost' and the other settings to match your SMTP.


2 Answers

If you have set up the local SMTP server then you should just provide connection details for that:

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

You should have that in your config/environments/*.rb files.

like image 88
HakonB Avatar answered Sep 30 '22 07:09

HakonB


In order to send emails you need to setup an smtp server. It could be setup locally or use a remote service like Gmail, SendGrid or Mandrill. In your case I would suggest using mailcatcher.

From the docs:

How

  1. gem install mailcatcher
  2. mailcatcher
  3. Go to http://localhost:1080/
  4. Send mail through smtp://localhost:1025

Rails

To set up your rails app, I recommend adding this to your environments/development.rb:

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

like image 20
Alexander Popov Avatar answered Sep 30 '22 08:09

Alexander Popov