2010-07-30 62 views
2

我試圖給用戶發送確認郵件。Net :: SMTPAuthenticationError 502 5.5.2在Rails中ActionMailer

,但我得到以下錯誤:在production.rb

Net::SMTPAuthenticationError (502 5.5.2 Error: command not recognized

配置如下:

# Disable delivery errors, bad email addresses will be ignored 
config.action_mailer.raise_delivery_errors = true 

# set delivery method to :smtp, :sendmail or :test 
config.action_mailer.delivery_method = :smtp 

# these options are only needed if you choose smtp delivery 
config.action_mailer.smtp_settings = { 
    :address  => 'path_to_address_specified_by_my_hoster', 
    :port   => 25, 
    :domain   => 'my_domain.com', 
    :authentication => :plain, 
    :user_name  => '[email protected]_domain.com', 
    :password  => 'password' 
} 

我已經在我的託管服務提供商,創建命名在用戶配置文件郵箱「註冊@ my_domain .com「

對於已創建郵箱,他們向我發出登錄名和密碼:

login = verbose_login

password = verbose_password

我沒有完全明白user_name的確切格式。

我應該用

:user_name => "[email protected]_domain.com" 

或:

:user_name => "signup" 

或:

:user_name => "verbose_login" 

或者該字段是針對郵件服務器,我要問的支持託管服務提供商的?

還有什麼區別:身份驗證=>:純文本和:登錄?

謝謝。

回答

5

這很適合我:

config.action_mailer.smtp_settings = { 
    :address    => 'smtp.gmail.com', 
    :port     => 587, 
    :domain    => 'gmail.com', 
    :user_name   => '[email protected]', 
    :password    => 'secret_password', 
    :authentication  => 'login', 
    :enable_starttls_auto => true 
    } 

更多信息here

切赫

+1

THX它可以幫助我。 :) – 2012-02-17 11:11:38

1

我已經得到了同樣的錯誤最近,原因是收件人的格式不正確

recipient = IO.readlines(emails_filename).first 
mail(:to => recipient, :subject => subject) 

不要忘了添加strip得到乾淨的電子郵件

0

請嘗試使用瀏覽器進行一次登錄。 登錄可能會有一些問題(它會詢問驗證碼等)。

成功登錄後,請嘗試使用Rails Mailer。 它應該現在工作。

這個問題通常發生在測試帳戶上,因爲我們通常不通過瀏覽器登錄。 然後郵件提供商要求確認captcha,dob或安全問題的答案等

1

我有同樣的問題,但它只是一個谷歌配置問題。

由於某些原因,Google阻止了從未知位置(應用程序在製作中)的訪問,因此要解決此問題,您可以前往http://www.google.com/accounts/DisplayUnlockCaptcha並點擊繼續(這將授予訪問10分鐘以註冊新應用程序)。

另一方面,您可以登錄到您的Gmail帳戶,然後去https://www.google.com/settings/security/lesssecureapps,並啓用訪問不太安全的應用程序,這是我的解決方案!

0

您對使用ActionMaliler :: Base的,而不是配置

ActionMailer::Base.smtp_settings #try this 

    config.action_mailer.smtp_settings #instead of this 

更改您的SMTP代碼的下方。它現在應該工作。

 ActionMailer::Base.smtp_settings = { 
     :address  => 'path_to_address_specified_by_my_hoster', 
     :port   => 25, 
     :domain   => 'my_domain.com', 
     :authentication => :plain, 
     :user_name  => '[email protected]_domain.com', 
     :password  => 'password' 
      }