Problem z wysylaniem e-mail -i!

Witam! Chciał bym wysyłać do użytkowników emaile, więc zgodnie ze znalezionymi poradami robie tak:

do configuration/environment.rb wrzucam:

[code] config.action_mailer.delivery_method = :smtp

config.action_mailer.server_settings = {
:address => ‘smtp.poczta.onet.pl’,
:port => 25,
:user_name => ‘nazwa_uzytkownika’,
:password => ‘haslo’
}[/code]
do configuration/environments/development.rb wrzucam:

[code]

config.action_mailer.perform_deliveries = true
cofnig.action_mailer.railse_delivery_errors = true[/code]
Po prubie uruchomienia wszystkiego wywala mi cos takiego:

[code]=> Booting WEBrick…

D:/kamil szkola/ruby/railsspace/MOTOMANIA/config/environment.rb:62: undefined local variable or method `config’ for main:Object (NameError)

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'

    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'

    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'

    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/webrick.rb:59

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'

    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'

    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'

    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'

    from script/server:3[/code]

Proszę bardzo o pomoc, bo nie mogę sobie poradzić z tym :confused:

  1. Cały environment.rb dawaj, być może wstawiłeś ten blok kodu przed/w bloku Initializera
  2. cofnig.action_mailer.railse_delivery_errors = true ? Przeczytaj to dobrze trzy razy :wink:

[code]# Be sure to restart your server when you modify this file

Uncomment below to force Rails into production mode when

you don’t control web/app server and can’t set it the proper way

ENV[‘RAILS_ENV’] ||= ‘production’

Specifies gem version of Rails to use when vendor/rails is not present

RAILS_GEM_VERSION = ‘2.0.2’ unless defined? RAILS_GEM_VERSION
DB_STRING_MAX_LENGTH = 255 #tutaj - dlatego, ze przyda sie nie tylko w modelu Spec

Bootstrap the Rails environment, frameworks, and default configuration

require File.join(File.dirname(FILE), ‘boot’)

Rails::Initializer.run do |config|

Settings in config/environments/* take precedence over those specified here.

Application configuration should go into files in config/initializers

– all .rb files in that directory are automatically loaded.

See Rails::Configuration for more options.

Skip frameworks you’re not going to use (only works if using vendor/rails).

To use Rails without a database, you must remove the Active Record framework

config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

Only load the plugins named here, in the order given. By default, all plugins

in vendor/plugins are loaded in alphabetical order.

:all can be used as a placeholder for all plugins not explicitly named

config.plugins = [ :exception_notification, :ssl_requirement, :all ]

Add additional load paths for your own custom dirs

config.load_paths += %W( #{RAILS_ROOT}/extras )

Force all environments to use the same logger level

(by default production uses :info, the others :debug)

config.log_level = :debug

Your secret key for verifying cookie session data integrity.

If you change this key, all old sessions will become invalid!

Make sure the secret is at least 30 characters and all random,

no regular words or you’ll be exposed to dictionary attacks.

config.action_controller.session = {
:session_key => ‘_MOTOMANIA_session’,
:secret => ‘09856b552d3027ee2067086ba8b66703908eea0d2afad9c84a5c67a967357741f056b4ae78e00d04c2a8e46c4ad05d428027d95950cfb1968a0051b0c54d9cc6’
}

Use the database for sessions instead of the cookie-based default,

which shouldn’t be used to store highly confidential information

(create the session table with ‘rake db:sessions:create’)

config.action_controller.session_store = :active_record_store

Use SQL instead of Active Record’s schema dumper when creating the test database.

This is necessary if your schema can’t be completely dumped by the schema dumper,

like if you have constraints or database-specific column types

config.active_record.schema_format = :sql

Activate observers that should always be running

config.active_record.observers = :cacher, :garbage_collector

Make Active Record use UTC-base instead of local time

config.active_record.default_timezone = :utc

end

config.action_mailer.delivery_method = :smtp

config.action_mailer.server_settings = {
:address => ‘smtp.poczta.onet.pl’,
:port => 25,
:domain => ‘onet.pl’,
:authentication => ‘rysic@vp.pl’,
:user_name => ‘rysic@vp.pl’,
:password => ‘4064g796413’
}

require “will_paginate”[/code]
Zakladam, ze pewnie gdzies zle to wstawilem, bo robie to pierwszy raz :confused:

W ksiazce mam tak napisane:

# Raise Errors if the mailer can't send config.action_mailer.raise_delivery_errors = true
EDIT:

ad. 2)
OK! Masz racje! :slight_smile: Na tej stronie bylo zle napisane: http://community.programuj.com/p/comboy/Wysyłanie%20maili%20w%20Ruby%20on%20Rails

Copy-paste programming czasem obsysa :wink:

I jak, poprawienie tej literówki usunęło problem?

Niestety nie :confused:

config.action_mailer.delivery_method masz poza blokiem Rails::Initializer.run do |config| … end dlatego zmienna “config” jest niezdefiniowana, przenieś to do bloku i będzie ok.

Niestety nadal: “from script/server:3”

Po pierwsze:
to troche mało informacji… więcej logów i zobacz czy napewno masz ten config w odpowiednim miejscu jak mówił hosiawak.
Po drugie:
na Boga, ten copy paste Cię zniszczy kiedyś,
wysyłam Ci wiadomość na priva i przeczytaj go uważnie.

pozdrawiam

Sorki za spam, ale juz chce dokladnie pokazac jak to u mnie wyglada:

[code]# Be sure to restart your server when you modify this file

Uncomment below to force Rails into production mode when

you don’t control web/app server and can’t set it the proper way

ENV[‘RAILS_ENV’] ||= ‘production’

Specifies gem version of Rails to use when vendor/rails is not present

RAILS_GEM_VERSION = ‘2.0.2’ unless defined? RAILS_GEM_VERSION
DB_STRING_MAX_LENGTH = 255 #tutaj - dlatego, ze przyda sie nie tylko w modelu Spec

Bootstrap the Rails environment, frameworks, and default configuration

require File.join(File.dirname(FILE), ‘boot’)

Rails::Initializer.run do |config|

Settings in config/environments/* take precedence over those specified here.

Application configuration should go into files in config/initializers

– all .rb files in that directory are automatically loaded.

See Rails::Configuration for more options.

Skip frameworks you’re not going to use (only works if using vendor/rails).

To use Rails without a database, you must remove the Active Record framework

config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

Only load the plugins named here, in the order given. By default, all plugins

in vendor/plugins are loaded in alphabetical order.

:all can be used as a placeholder for all plugins not explicitly named

config.plugins = [ :exception_notification, :ssl_requirement, :all ]

Add additional load paths for your own custom dirs

config.load_paths += %W( #{RAILS_ROOT}/extras )

Force all environments to use the same logger level

(by default production uses :info, the others :debug)

config.log_level = :debug

Your secret key for verifying cookie session data integrity.

If you change this key, all old sessions will become invalid!

Make sure the secret is at least 30 characters and all random,

no regular words or you’ll be exposed to dictionary attacks.

config.action_controller.session = {
:session_key => ‘_MOTOMANIA_session’,
:secret => ‘09856b552d3027ee2067086ba8b66703908eea0d2afad9c84a5c67a967357741f056b4ae78e00d04c2a8e46c4ad05d428027d95950cfb1968a0051b0c54d9cc6’
}

Use the database for sessions instead of the cookie-based default,

which shouldn’t be used to store highly confidential information

(create the session table with ‘rake db:sessions:create’)

config.action_controller.session_store = :active_record_store

Use SQL instead of Active Record’s schema dumper when creating the test database.

This is necessary if your schema can’t be completely dumped by the schema dumper,

like if you have constraints or database-specific column types

config.active_record.schema_format = :sql

Activate observers that should always be running

config.active_record.observers = :cacher, :garbage_collector

Make Active Record use UTC-base instead of local time

config.active_record.default_timezone = :utc

config.action_mailer.delivery_method = :smtp

end

config.action_mailer.server_settings =
{
:address => ‘smtp.poczta.onet.pl’,
:port => 25,
:domain => ‘onet.pl’,
:authentication => :login,
:user_name => ‘rysic@vp.pl’,
:password => ‘123’
}

require “will_paginate”[/code]
Wtedy wywala:

[code]=> Booting WEBrick…

D:/kamil szkola/ruby/railsspace/MOTOMANIA/config/environment.rb:67: undefined local variable or method `config’ for main:Object (NameError)

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'

    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'

    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'

    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/webrick.rb:59

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'

    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'

    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'

    from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'

    from script/server:3[/code]

Nie wiem, czy nie powinienem tez ‘config.action_mailer.server_settings’ umiescic w srodku. Czyli:

[code]# Be sure to restart your server when you modify this file

Uncomment below to force Rails into production mode when

you don’t control web/app server and can’t set it the proper way

ENV[‘RAILS_ENV’] ||= ‘production’

Specifies gem version of Rails to use when vendor/rails is not present

RAILS_GEM_VERSION = ‘2.0.2’ unless defined? RAILS_GEM_VERSION
DB_STRING_MAX_LENGTH = 255 #tutaj - dlatego, ze przyda sie nie tylko w modelu Spec

Bootstrap the Rails environment, frameworks, and default configuration

require File.join(File.dirname(FILE), ‘boot’)

Rails::Initializer.run do |config|

Settings in config/environments/* take precedence over those specified here.

Application configuration should go into files in config/initializers

– all .rb files in that directory are automatically loaded.

See Rails::Configuration for more options.

Skip frameworks you’re not going to use (only works if using vendor/rails).

To use Rails without a database, you must remove the Active Record framework

config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

Only load the plugins named here, in the order given. By default, all plugins

in vendor/plugins are loaded in alphabetical order.

:all can be used as a placeholder for all plugins not explicitly named

config.plugins = [ :exception_notification, :ssl_requirement, :all ]

Add additional load paths for your own custom dirs

config.load_paths += %W( #{RAILS_ROOT}/extras )

Force all environments to use the same logger level

(by default production uses :info, the others :debug)

config.log_level = :debug

Your secret key for verifying cookie session data integrity.

If you change this key, all old sessions will become invalid!

Make sure the secret is at least 30 characters and all random,

no regular words or you’ll be exposed to dictionary attacks.

config.action_controller.session = {
:session_key => ‘_MOTOMANIA_session’,
:secret => ‘09856b552d3027ee2067086ba8b66703908eea0d2afad9c84a5c67a967357741f056b4ae78e00d04c2a8e46c4ad05d428027d95950cfb1968a0051b0c54d9cc6’
}

Use the database for sessions instead of the cookie-based default,

which shouldn’t be used to store highly confidential information

(create the session table with ‘rake db:sessions:create’)

config.action_controller.session_store = :active_record_store

Use SQL instead of Active Record’s schema dumper when creating the test database.

This is necessary if your schema can’t be completely dumped by the schema dumper,

like if you have constraints or database-specific column types

config.active_record.schema_format = :sql

Activate observers that should always be running

config.active_record.observers = :cacher, :garbage_collector

Make Active Record use UTC-base instead of local time

config.active_record.default_timezone = :utc

config.action_mailer.delivery_method = :smtp
config.action_mailer.server_settings =
{
:address => ‘smtp.poczta.onet.pl’,
:port => 25,
:domain => ‘onet.pl’,
:authentication => :login,
:user_name => ‘rysic@vp.pl’,
:password => ‘123’
}

end

require “will_paginate”[/code]
Jak tak zrobie, to wywala:

[code]=> Booting WEBrick…

c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-2.0.2/lib/action_mailer/base.rb:354:in method_missing': undefined methodserver_settings=’ for ActionMailer::Base:Class (NoMethodError)

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:328:in `send'

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:328:in `initialize_framework_settings'

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:327:in `each'

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:327:in `initialize_framework_settings'

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:324:in `each'

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:324:in `initialize_framework_settings'

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:101:in `process'

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:49:in `send'

     ... 13 levels...

    from c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'

    from c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'

    from script/server:3[/code]

Co do tego, ze malo informacji, to NetBeans mi tylko to wyrzuca. Co do copy paste, to macie racje. Musze sie nawrocic :wink: Za szybko bym chcial wszystko zrobic…

zamiast

config.action_mailer.server_settings

powinno być

config.action_mailer.smtp_settings

:slight_smile:

Dalej nie przeczytałeś mojego maila.

pozdrawiam

Skapnalem sie sam przed przeczytaniem go :smiley: ale dzieki. To wszystko z pospiechu :confused: robie parce lic i troszke sobie zostawilem na ostatnia chwile :stuck_out_tongue_winking_eye: Ostatnia porada dziala. Wielkie dzieki za pomoc! Jesli dobrze sobie doczytalem, to server_settings zostalo wycofane, tak?

Żeby nie zaczynać nowego tematu, to napiszę jeszcze tutaj, bo wysyłanie poczty jeszcze nie do końca działa.

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings =
{
:address => ‘smtp.wp.pl’,
:port => 25,

:authentication => :login,
:user_name => 'przykladowamoto',
:password => 'koko11'

}

Tak wyglądają moje ustawienia poczty (konto jest prawdziwe - nic ciekawego tam nie ma [ więc proszę nie zmiieniać hasła :wink: ] , więc można sprawdzić, ze login i hasło działają).

Dostaje taki błąd:

535 Authentication failed / Niepoprawna autoryzacja

http://apidock.com/ruby/Net/SMTP

Odszukaj sekcję SMTP Authentication i przeczytaj, jesteś pewny, że powinieneś użyć :login do twojego serwera ?

Masz racje HOSIAWAK! Po usunieciu wogle tej linijki zaczelo dzialac. Choc… szczerze powiem, to nie do konca wiem dlaczego :confused: Ten link, ktory mi dales nie duzo mi mowi. Jak by ktos mogl objasnic dlaczego to nie dzialalo, to byl bym wdzieczny. Wielkie dzieki za pomoc. Pozdrawiam!