2013-11-15 74 views
0

我有一個Rails應用程序,它使用表單收集消息詳細信息並通過電子郵件將消息發送到我的gmail/yahoo帳戶。操作郵件程序錯誤:535-5.7.8用戶名和密碼不被接受

我已經加入這個在配置/初始化爲setup_mail.rb:

ActionMailer::Base.smtp_settings = { 
     :address    => "smtp.gmail.com", 
     :port     => 587, 
     :user_name   => "my_user", 
     :password    => "my_pass", 
     :authentication  => "plain", 
     :enable_starttls_auto => true 
    } 

和使用控制器,像這樣的POST路線:

def create 
    @message = Message.new(params[:message]) 

    if @message.valid? 
     NotificationsMailer.new_message(@message).deliver! 
     redirect_to(root_path, :notice => "Message was successfully sent.") 
    else 
     flash.now.alert = "Please fill all fields." 
     redirect_to('#') 
    end 
end 

消息參數是從接受的形式乾淨像這樣:

Parameters: {"utf8"=>"✓", "authenticity_token"=>"4xgV0umvaTPzYxd18qdJq/GT7QCdXjrPTGR7D9R3AC4=", "message"=>{"name"=>"Deepak", "email"=>"[email protected]", "subject"=>"Hi", "body"=>"Hi"}, "commit"=>"Send"} 

無論我使用的是Yahoo憑證還是Gmail憑證e設置,我不斷收到相同的錯誤信息。我評論了ActionMailer :: Base.smtp_settings中的所有設置,但仍然遇到此問題。這使我相信這個問題可能與此代碼之外的其他內容有關,但我不知道。

-Deepak

+0

您是否允許外部連接在您的Google帳戶首選項中發送電子郵件? – okliv

+0

我看不到傳出郵件的設置。我已經啓用了Gmail上的IMAP設置,但仍然是相同的錯誤。它是否正確?傳出和傳入的郵件都來自我的gmail ID。 – user2738707

+1

當我有同樣的問題,並登錄到谷歌郵件時,我看到有人想從外部發送我的帳戶的電子郵件的頁面頂部的通知字符串。並有一個按鈕 - 允許此操作(或類似的東西),也檢查用戶名是否以'@ gmail.com'結尾 – okliv

回答

0

你提到你的代碼是在config/initializers - 我們有ActionMailer工作,並把它發送通過Gmail,但我們要把它放到我們的config/environments/developer.rb文件:

#Send Email In Development (Use Gmail's Servers) 
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.perform_deliveries = true 
    config.action_mailer.smtp_settings = { 
     :address    => "smtp.gmail.com", 
     :port     => 587, 
     :domain    => "*****.co.uk", 
     :user_name   => "******@gmail.com", 
     :password    => "******", 
     :authentication  => :plain, 
     :enable_starttls_auto => true 
    } 
    config.action_mailer.default_url_options = { 
     :host => "localhost:3000" 
    } 

也許你可以嘗試複製 - 粘貼上面的代碼?

+0

感謝您的提示。我嘗試了這些設置,不添加域密鑰,因爲我沒有使用谷歌應用程序,並啓用IMAP。我收到了同樣的信息:535-5.7.8用戶名和密碼未被接受。有沒有我可以做的調試來調試這個錯誤來自哪裏? – user2738707

+0

你確定你可以使用IMAP發送嗎?我確定它只是用於檢索。也許這是一個問題? –

+0

根據文檔,必須啓用IMAP以讀取外部客戶端上的消息,並使用SMTP從外部客戶端發送消息。我認爲IMAP不需要啓用ActionMailer工作。 https://support.google.com/mail/troubleshooter/1668960?rd=1#ts=1665018,1665144。它可能是防火牆的問題嗎? – user2738707

0

雖然我仍然無法通過ActionMailer發送電子郵件,但我還是想發佈一個替代方案。

https://github.com/nu7hatch/gmail

運作良好,並更容易,因爲你不需要使用任何配置文件。

謝謝。

相關問題