2014-07-05 58 views
1

所以我遇到了一個我從未見過的有趣的錯誤。我試圖在開發中設置郵件,以便我可以發送實際的電子郵件給我自己。所以,讓我們去通過我如何設定了郵件在Rails 4.1中發送郵件

我有一個名爲setup_mail.rb

ActionMailer::Base.smtp_settings = { 
    :address => 'smptp.gmail.com', 
    :port => 587, 
    :domain => "gmail.com", 
    :user_name => Figaro.env.EMAIL, 
    :password => Figaro.env.PASSWORD, 
    :authentication => 'plain', 
    :enable_starttls_auto => true 
} 

ActionMailer::Base.default_url_options[:host] = Figaro.env.HOST 

從那裏,我們叫user_mailer.rb

class UserMailer < ActionMailer::Base 
    default from: "[email protected]" 

    def registration_confirmation(user) 
    @user = user 
    mail(:to => "#{user.first_name} <#{user.email}>", :subject => 'Welcome to AisisPlatform!') 
    end 

    def password_reset(user) 
    @user = user 
    mail(:to => "#{user.first_name} <#{user.email}>", :subject => 'Password Reset (AisisPlatform)') 
    end 
end 

的郵寄目錄有一個郵件類的初始化它有它的所述郵件的HTML和非HTML版本的適當視圖。然後,我們這樣做:

UserMailer.registration_confirmation(@user).deliver 
在用戶 create控制器

發送郵件,但在提交形式和創建用戶我瞬間得到:

SocketError (getaddrinfo: nodename nor servname provided, or not known) 

所以我想,讓我們看看日誌(警告它很長):

UserMailer#registration_confirmation: processed outbound mail in 520.0ms 

Sent mail to [email protected] (89.3ms) 
Date: Fri, 04 Jul 2014 19:36:17 -0600 
From: [email protected] 
To: trolololololololo <[email protected]> 
Message-ID: <[email protected]> 
Subject: Welcome to AisisPlatform! 
Mime-Version: 1.0 
Content-Type: multipart/alternative; 
boundary="--==_mimepart_53b756918f0f4_957f3fc5b1ce122c93864"; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 


----==_mimepart_53b756918f0f4_957f3fc5b1ce122c93864 
Content-Type: text/plain; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 

trolololololololo, 

Welcome and thank you for signing up to AisisPlatform. 

We believe that our small, simple and yet very powerful API will allow you to create blog you have always wanted to create. 
We are constently growing and evolving the feature set and coming out with new ideas and concepts we hope to share with you. 

We are more then grateful for your participation in our services and hope we can be of use to you in any way shape or form that will 
help make you happy and excited to use and share our services and products.< 

sincerly, 

AisisPlatform 

----==_mimepart_53b756918f0f4_957f3fc5b1ce122c93864 
Content-Type: text/html; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 

<h3>trolololololololo,</h3> 

<p>Welcome and thank you for signing up to AisisPlatform.</p> 

<p>We believe that our small, simple and yet very powerful API will allow you to create blog you have always wanted to create. 
We are constently growing and evolving the feature set and coming out with new ideas and concepts we hope to share with you.</p> 

<p>We are more then grateful for your participation in our services and hope we can be of use to you in any way shape or form that will 
help make you happy and excited to use and share our services and products.</p> 

<p>sincerly,</p> 

<p><em>AisisPlatform</em></p> 

----==_mimepart_53b756918f0f4_957f3fc5b1ce122c93864-- 

Completed 500 Internal Server Error in 1048ms 

SocketError (getaddrinfo: nodename nor servname provided, or not known): 
    /Users/Adam/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/smtp.rb:541:in `initialize' 
    /Users/Adam/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/smtp.rb:541:in `open' 
    /Users/Adam/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/smtp.rb:541:in `tcp_socket' 
    /Users/Adam/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/smtp.rb:551:in `block in do_start' 
    /Users/Adam/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/timeout.rb:91:in `block in timeout' 
    /Users/Adam/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/timeout.rb:101:in `call' 
    /Users/Adam/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/timeout.rb:101:in `timeout' 
    /Users/Adam/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/smtp.rb:550:in `do_start' 
    /Users/Adam/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/smtp.rb:520:in `start' 
    mail (2.5.4) lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!' 
    mail (2.5.4) lib/mail/message.rb:2129:in `do_delivery' 
    mail (2.5.4) lib/mail/message.rb:232:in `block in deliver' 
    actionmailer (4.1.0) lib/action_mailer/base.rb:527:in `block in deliver_mail' 
    activesupport (4.1.0) lib/active_support/notifications.rb:159:in `block in instrument' 
    activesupport (4.1.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
    activesupport (4.1.0) lib/active_support/notifications.rb:159:in `instrument' 
    actionmailer (4.1.0) lib/action_mailer/base.rb:525:in `deliver_mail' 
    mail (2.5.4) lib/mail/message.rb:232:in `deliver' 
    /Users/Adam/.rvm/gems/ruby-2.1.1/bundler/gems/Xaaron-2ee49cf0018e/app/controllers/xaaron/users_controller.rb:20:in `create' 
    actionpack (4.1.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action' 
    actionpack (4.1.0) lib/abstract_controller/base.rb:189:in `process_action' 
    actionpack (4.1.0) lib/action_controller/metal/rendering.rb:10:in `process_action' 
    actionpack (4.1.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:113:in `call' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:113:in `call' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:149:in `block in halting_and_conditional' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:229:in `call' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:229:in `block in halting' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:229:in `call' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:229:in `block in halting' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `call' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `block in halting' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `call' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `block in halting' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `call' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:166:in `block in halting' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:86:in `call' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:86:in `run_callbacks' 
    actionpack (4.1.0) lib/abstract_controller/callbacks.rb:19:in `process_action' 
    actionpack (4.1.0) lib/action_controller/metal/rescue.rb:29:in `process_action' 
    actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action' 
    activesupport (4.1.0) lib/active_support/notifications.rb:159:in `block in instrument' 
    activesupport (4.1.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
    activesupport (4.1.0) lib/active_support/notifications.rb:159:in `instrument' 
    actionpack (4.1.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action' 
    actionpack (4.1.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action' 
    activerecord (4.1.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action' 
    /Users/Adam/.rvm/gems/ruby-2.1.1/bundler/gems/promiscuous-9bda9a49ac13/gemfiles/lib/promiscuous/railtie.rb:6:in `process_action' 
    actionpack (4.1.0) lib/abstract_controller/base.rb:136:in `process' 
    actionview (4.1.0) lib/action_view/rendering.rb:30:in `process' 
    actionpack (4.1.0) lib/action_controller/metal.rb:195:in `dispatch' 
    actionpack (4.1.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch' 
    actionpack (4.1.0) lib/action_controller/metal.rb:231:in `block in action' 
    actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:80:in `call' 
    actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:80:in `dispatch' 
    actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:48:in `call' 
    actionpack (4.1.0) lib/action_dispatch/journey/router.rb:71:in `block in call' 
    actionpack (4.1.0) lib/action_dispatch/journey/router.rb:59:in `each' 
    actionpack (4.1.0) lib/action_dispatch/journey/router.rb:59:in `call' 
    actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:676:in `call' 
    railties (4.1.0) lib/rails/engine.rb:514:in `call' 
    railties (4.1.0) lib/rails/railtie.rb:194:in `public_send' 
    railties (4.1.0) lib/rails/railtie.rb:194:in `method_missing' 
    actionpack (4.1.0) lib/action_dispatch/journey/router.rb:71:in `block in call' 
    actionpack (4.1.0) lib/action_dispatch/journey/router.rb:59:in `each' 
    actionpack (4.1.0) lib/action_dispatch/journey/router.rb:59:in `call' 
    actionpack (4.1.0) lib/action_dispatch/routing/route_set.rb:676:in `call' 
    rack (1.5.2) lib/rack/etag.rb:23:in `call' 
    rack (1.5.2) lib/rack/conditionalget.rb:35:in `call' 
    rack (1.5.2) lib/rack/head.rb:11:in `call' 
    actionpack (4.1.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call' 
    actionpack (4.1.0) lib/action_dispatch/middleware/flash.rb:254:in `call' 
    rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context' 
    rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call' 
    actionpack (4.1.0) lib/action_dispatch/middleware/cookies.rb:560:in `call' 
    activerecord (4.1.0) lib/active_record/query_cache.rb:36:in `call' 
    activerecord (4.1.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:621:in `call' 
    activerecord (4.1.0) lib/active_record/migration.rb:380:in `call' 
    actionpack (4.1.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' 
    activesupport (4.1.0) lib/active_support/callbacks.rb:82:in `run_callbacks' 
    actionpack (4.1.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
    actionpack (4.1.0) lib/action_dispatch/middleware/reloader.rb:73:in `call' 
    actionpack (4.1.0) lib/action_dispatch/middleware/remote_ip.rb:76:in `call' 
    actionpack (4.1.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call' 
    actionpack (4.1.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
    railties (4.1.0) lib/rails/rack/logger.rb:38:in `call_app' 
    railties (4.1.0) lib/rails/rack/logger.rb:20:in `block in call' 
    activesupport (4.1.0) lib/active_support/tagged_logging.rb:68:in `block in tagged' 
    activesupport (4.1.0) lib/active_support/tagged_logging.rb:26:in `tagged' 
    activesupport (4.1.0) lib/active_support/tagged_logging.rb:68:in `tagged' 
    railties (4.1.0) lib/rails/rack/logger.rb:20:in `call' 
    actionpack (4.1.0) lib/action_dispatch/middleware/request_id.rb:21:in `call' 
    rack (1.5.2) lib/rack/methodoverride.rb:21:in `call' 
    rack (1.5.2) lib/rack/runtime.rb:17:in `call' 
    activesupport (4.1.0) lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call' 
    rack (1.5.2) lib/rack/lock.rb:17:in `call' 
    actionpack (4.1.0) lib/action_dispatch/middleware/static.rb:64:in `call' 
    rack (1.5.2) lib/rack/sendfile.rb:112:in `call' 
    railties (4.1.0) lib/rails/engine.rb:514:in `call' 
    railties (4.1.0) lib/rails/application.rb:144:in `call' 
    rack (1.5.2) lib/rack/lock.rb:17:in `call' 
    rack (1.5.2) lib/rack/content_length.rb:14:in `call' 
    rack (1.5.2) lib/rack/handler/webrick.rb:60:in `service' 
    /Users/Adam/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service' 
    /Users/Adam/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run' 
    /Users/Adam/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread' 


    Rendered /Users/Adam/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (0.5ms) 
    [1m[36mPromiscuous Recovery Delete (23.8ms)[0m [1mDELETE FROM _promiscuous WHERE id = 17[0m 
    Rendered /Users/Adam/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.0ms) 
    Rendered /Users/Adam/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.0ms) 
    Rendered /Users/Adam/.rvm/gems/ruby-2.1.1/gems/actionpack-4.1.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (15.3ms) 

這是怎麼回事?爲什麼我得到這個錯誤?我跟着Ryan Bates設置郵件。它過時了嗎?

回答

2

錯誤告訴您Ruby無法找到SMTP服務器的DNS條目。

這是因爲您在配置中存在拼寫錯誤,其smtp.gmail.com而不是smptp.gmail.com。此外,domain應該是你的域,而不是gmail.com

ActionMailer::Base.smtp_settings = { 
    :address    => 'smtp.gmail.com', 
    :port     => 587, 
    :domain    => 'aisisplanner.com', 
    :user_name   => Figaro.env.EMAIL, 
    :password    => Figaro.env.PASSWORD, 
    :authentication  => 'plain', 
    :enable_starttls_auto => true 
} 

見:「假的電子郵件」 http://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-configuration-for-gmail

+0

那認真的方式它像有沒有辦法趕上,並像「確保我們會發送它在那裏.....好運得到它」 – user3379926

+0

所以這不起作用,因爲當我看到什麼e.message甚至與我自己的個人電子郵件我得到了這個:''getaddrinfo:nodename也沒有提供服務器名稱,或不知道「 – user3379926