Tôi đã thử tất cả các loại cấu hình nhưng tôi vẫn không thể gửi email trong môi trường phát triển của mình từ đường ray.Rails 3 mailer không hoạt động và không ghi lại bất kỳ lỗi nào
Tôi đã cài đặt thư để thử điều này từ dòng lệnh và nó hoạt động, tôi nhận được email (trong thư rác tất nhiên): echo test | Thư -s Chủ đề [email protected]
Dưới đây là cấu hình của tôi:
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true # still no logs about emails
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true # I can't believe I have to add this option. Does it even exist? I found it on google.
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => :login,
:user_name => "[email protected]",
:password => "abc123",
}
Và đây là mã trong bưu phẩm:
class UserMailer < ActionMailer::Base
default :from => "[email protected]"
def test_email
Rails.logger.debug 'test_email'
mail(:to => '[email protected]', :subject => "testing rails")
end
end
Bộ điều khiển:
class PagesController < ApplicationController
def home
UserMailer.test_email
end
end
phát triển .log:
[2012-03-01 18:26:45.859] DEBUG [bb44dee806d73eb60ab3ae16297f5c02] [127.0.0.1] [GET] [http://myapp:3000/] test_email
[2012-03-01 18:26:45.888] INFO [bb44dee806d73eb60ab3ae16297f5c02] [127.0.0.1] [GET] [http://myapp:3000/] Rendered user_mailer/test_email (1.6ms)
[2012-03-01 18:26:45.898] INFO [bb44dee806d73eb60ab3ae16297f5c02] [127.0.0.1] [GET] [http://myapp:3000/] Rendered pages/home.html.erb within layouts/application (1.1ms)
[2012-03-01 18:26:46.815] INFO [bb44dee806d73eb60ab3ae16297f5c02] [127.0.0.1] [GET] [http://myapp:3000/] Completed 200 OK in 455ms (Views: 112.4ms)
Tôi cũng đã cố gắng sử dụng giao diện điều khiển:
[email protected]:/srv/www/myapp# rails c
Loading development environment (Rails 3.2.1)
irb(main):001:0> UserMailer.test_email
=> #<Mail::Message:32110400, Multipart: false, Headers: <To: [email protected]>, <Subject: testing rails>, <Mime-Version: 1.0>, <Content-Type: text/html>>
http://guides.rubyonrails.org/action_mailer_basics.html có ví dụ về cấu hình Gmail. Nó sử dụng 'plain' cho thuộc tính xác thực, bạn đã thử nó chưa? – ismriv
vâng tôi đã thử nó và không có gì xảy ra. Nếu không có bất kỳ nhật ký nào, điều này sẽ không hoạt động. Mọi thứ khác trong yêu cầu được ghi chính xác – HappyDeveloper
Mã nào gọi trình gửi như thế nào? –