Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails rails邮件程序:未发送电子邮件_Ruby On Rails_Email_Mailer - Fatal编程技术网

Ruby on rails rails邮件程序:未发送电子邮件

Ruby on rails rails邮件程序:未发送电子邮件,ruby-on-rails,email,mailer,Ruby On Rails,Email,Mailer,我正在尝试让Rails发送电子邮件。这似乎是工作,我没有得到任何错误在我的本地服务器,但我不能收到任何电子邮件。一切似乎都很好,只是因为没有抛出错误,但是电子邮件没有被发送 应用程序_mailer.rb class ApplicationMailer < ActionMailer::Base default from: 'test@example.com' layout 'send_message' end application.rb 我已经尝试了几种不同的方法,一种是不修改这

我正在尝试让Rails发送电子邮件。这似乎是工作,我没有得到任何错误在我的本地服务器,但我不能收到任何电子邮件。一切似乎都很好,只是因为没有抛出错误,但是电子邮件没有被发送

应用程序_mailer.rb

class ApplicationMailer < ActionMailer::Base
  default from: 'test@example.com'
  layout 'send_message'
end
application.rb

我已经尝试了几种不同的方法,一种是不修改这个文件,另一种是修改下面的内容

    config.action_mailer.default_url_options = { :host => 'localhost:3000'    }
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
    :enable_starttls_auto => true,
    :address => 'smtp.gmail.com',
    :port => '25',
    :authentication => :plain,
    :domain => 'gmail.com',
    :user_name => 'my_gmail_email@gmail.com',
    :password => 'password'
  }
在我的控制器中发送电子邮件的位置

  def create

    @collected_email = CollectedEmail.new(collected_email_params)

    if @collected_email.save
      Mailer.send_message.deliver_now
      render json: @collected_email, status: :created, location: @collected_email
    else
      render json: @collected_email.errors, status: :unprocessable_entity
    end
  end
我有两个视图/布局和视图/邮件。我不知道为什么这是必要的,但如果我删除一个邮件程序不工作。在每个视图文件夹中,我都有一个send_message.html.erb和一个send_message.text.erb,它们非常简单,并且在每个视图文件夹中完全相同

send_message.text.erb

tester123
send_message.html.erb

<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1>Welcome to example.com</h1>
    <p>
      You have successfully signed up to example.com,
      your username is:<br>
    </p>
    <p>
      To login to the site, just follow this link.
    </p>
    <p>Thanks for joining and have a great day!</p>
  </body>
</html>
这是我的一个条目的服务器日志

Started POST "/collected_emails" for ::1 at 2015-08-06 21:09:22 -0400
  ActiveRecord::SchemaMigration Load (0.4ms)  SELECT "schema_migrations".*   FROM "schema_migrations"
Processing by CollectedEmailsController#create as */*
  Parameters: {"collected_email"=>{"email"=>"afsdlkjafs@asdfljk.cc"}}
   (0.2ms)  BEGIN
  CollectedEmail Exists (0.9ms)  SELECT  1 AS one FROM "collected_emails"   WHERE ("collected_emails"."email" = 'afsdlkjafs@asdfljk.cc' AND    "collected_emails"."email" = 'afsdlkjafs@asdfljk.cc') LIMIT 1
  SQL (0.4ms)  INSERT INTO "collected_emails" ("email", "created_at",    "updated_at") VALUES ($1, $2, $3) RETURNING "id"  [["email",   "afsdlkjafs@asdfljk.cc"], ["created_at", "2015-08-07 01:09:22.533596"],    ["updated_at", "2015-08-07 01:09:22.533596"]]
   (14.9ms)  COMMIT
  Rendered mailer/send_message.html.erb within layouts/send_message (2.2ms)
  Rendered mailer/send_message.text.erb within layouts/send_message (0.6ms)

Mailer#send_message: processed outbound mail in 426.4ms 

Sent mail to testeremail@email.com (30020.6ms)
Date: Thu, 06 Aug 2015 21:09:23 -0400
From: test@example.com
To: testeremail@email.com
Message-ID: <55c405439564_42a63fd0b5b8f02c676b8@William-Sargents-MacBook-   Pro.local.mail>
Subject: Sample Email
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_55c4054363e0_42a63fd0b5b8f02c67578";
 charset=UTF-8
Content-Transfer-Encoding: 7bit


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

tester123

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

<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1>Welcome to example.com</h1>
    <p>
      You have successfully signed up to example.com,
      your username is:<br>
    </p>
    <p>
      To login to the site, just follow this link.
    </p>
    <p>Thanks for joining and have a great day!</p>
  </body>
</html>

----==_mimepart_55c4054363e0_42a63fd0b5b8f02c67578--

Completed 201 Created in 30677ms (Views: 1.4ms | ActiveRecord: 19.4ms)

config.action\u mailer.raise\u delivery\u errors=false如果您希望在开发过程中引发错误,为什么这是false?请尝试config.action\u mailer.delivery\u method=:文件以查看邮件是否在tmp/mails/config.action\u mailer.raise\u delivery\u errors=false如果您希望在开发过程中引发错误,为什么这是false?请尝试config.action\u mailer.delivery\u method=:查看邮件是否在tmp/mails中生成的文件/
<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1>Welcome to example.com</h1>
    <p>
      You have successfully signed up to example.com,
      your username is:<br>
    </p>
    <p>
      To login to the site, just follow this link.
    </p>
    <p>Thanks for joining and have a great day!</p>
  </body>
</html>
Started POST "/collected_emails" for ::1 at 2015-08-06 21:09:22 -0400
  ActiveRecord::SchemaMigration Load (0.4ms)  SELECT "schema_migrations".*   FROM "schema_migrations"
Processing by CollectedEmailsController#create as */*
  Parameters: {"collected_email"=>{"email"=>"afsdlkjafs@asdfljk.cc"}}
   (0.2ms)  BEGIN
  CollectedEmail Exists (0.9ms)  SELECT  1 AS one FROM "collected_emails"   WHERE ("collected_emails"."email" = 'afsdlkjafs@asdfljk.cc' AND    "collected_emails"."email" = 'afsdlkjafs@asdfljk.cc') LIMIT 1
  SQL (0.4ms)  INSERT INTO "collected_emails" ("email", "created_at",    "updated_at") VALUES ($1, $2, $3) RETURNING "id"  [["email",   "afsdlkjafs@asdfljk.cc"], ["created_at", "2015-08-07 01:09:22.533596"],    ["updated_at", "2015-08-07 01:09:22.533596"]]
   (14.9ms)  COMMIT
  Rendered mailer/send_message.html.erb within layouts/send_message (2.2ms)
  Rendered mailer/send_message.text.erb within layouts/send_message (0.6ms)

Mailer#send_message: processed outbound mail in 426.4ms 

Sent mail to testeremail@email.com (30020.6ms)
Date: Thu, 06 Aug 2015 21:09:23 -0400
From: test@example.com
To: testeremail@email.com
Message-ID: <55c405439564_42a63fd0b5b8f02c676b8@William-Sargents-MacBook-   Pro.local.mail>
Subject: Sample Email
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_55c4054363e0_42a63fd0b5b8f02c67578";
 charset=UTF-8
Content-Transfer-Encoding: 7bit


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

tester123

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

<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1>Welcome to example.com</h1>
    <p>
      You have successfully signed up to example.com,
      your username is:<br>
    </p>
    <p>
      To login to the site, just follow this link.
    </p>
    <p>Thanks for joining and have a great day!</p>
  </body>
</html>

----==_mimepart_55c4054363e0_42a63fd0b5b8f02c67578--

Completed 201 Created in 30677ms (Views: 1.4ms | ActiveRecord: 19.4ms)