2016-07-27 14 views
4

私は単純なブログ(レール5を使用)を作成しようとしています。私は、actionmailerを使用しようとしていると私はユーザーを登録するdeviseを使用しています。私は最初のユーザーだけでそれを設定しようとしています。アクションメーラは電子メールの送受信をしません5

私のローカルサーバーを見ると、電子メールは送信されているように見えますが受信されません。どんなアドバイスも大歓迎です。

UserNotifierMailer#sample_email: processed outbound mail in 410.4ms 
Sent mail to [email protected] (853.2ms) 
Date: Wed, 27 Jul 2016 12:05:33 +0100 
From: [email protected] 
To:[email protected] 
Message-ID: <[email protected]me.mail> 
Subject: Sample Email 
Mime-Version: 1.0 
Content-Type: multipart/alternative; 
boundary="--==_mimepart_5798957d951e2_ae813ff962abfe1466312"; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 

マイポスト・コントローラは、次のようになります。

class UserNotifierMailer < ApplicationMailer 
    default from: "[email protected]" 
    def sample_email(user) 
    @user = user 
    @url = 'http://www.google.com' 
    mail(to: @user.email, subject: 'Sample Email') 
    end 
end 

と私development.rbに、私はこれらの設定を持っている:

config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.perform_deliveries = true 
    config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } 

    config.action_mailer.delivery_method = :smtp 

    config.action_mailer.smtp_settings = { 
    address: "smtp.gmail.com", 
    port: 587, 
    domain: "gmail.com", 
    authentication: "plain", 
    enable_starttls_auto: true, 
    user_name: "my_gmail_username", 
    password: "my_gmail_password" 
    } 

def create 
    @user = User.first 
    @post = current_user.posts.build(post_params) 
    if @post.save 
     flash[:success] = "Your post has been created!" 
     UserNotifierMailer.sample_email(@user).deliver 
     redirect_to posts_path 
    else 
     flash[:alert] = "Your new post couldn't be created! Please check the form." 
     render :new 
    end 
    end 

私のメーラーは、このようになります

+0

に動作しません。 com/settings/security/lesssecureapps – Deep

+0

私はついにそれを働かせました。それはGoogleの2段階認証と関係していました。それがオフになっていることを確認してください! –

答えて

2

設定済みのGmailでCCOUNT:接続されたアプリが続く

より
  • ゴー&サインインし、セキュリティ

    1. ゴーにアカウント設定、で最後に&サイト

    2. 以下を許可しますセキュアアプリ ...それを確認してください。

    3. 一度

    チェックし

  • 0
    config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.perform_deliveries = true 
    ... 
    config.action_mailer.delivery_method = :smtp 
    

    を試してみて、私は、上記のいずれかをconfigコンず、それはまだ動作します。 https://www.google:

    .deliver_laterまたは .deliver_now
    config.action_mailer.default_url_options = { host: 'localhost:3000' } 
    

    と持って、.deliver Googleアカウント(それが役立つかどうかわからない)でこの機能をに変更してみてください

    +0

    私はブロッククォートで上記のコードをラップしました。質問のコードを参照しているようです。これが間違っている場合は、[改訂履歴](http://stackoverflow.com/posts/40966354/revisions)の変更を展開するか、投稿を[編集]してさらに改善することができます。私は最後の文が何を意味するのか分かりません。 –

    関連する問題