Rails 4 ActionMailer没有在开发模式下发送电子邮件

时间:2023-01-16 10:00:08

First, let me specify that I am aware that ActionMailer does NOT send emails by default in development mode.

首先,让我指定我知道ActionMailer在开发模式下默认不发送电子邮件。

Also, I took a look at similar questions, and none of them was relevant to my situation.

另外,我也看了类似的问题,没有一个与我的情况有关。

So, here we go:

所以,我们开始吧:

  1. I am following this Site Point tutorial by Ilya Bodrov-Krukowski, from March 26, 2015 in order to install and setup Devise on my Rails 4 app.

    我正在遵循Ilya Bodrov-Krukowski于2015年3月26日编写的站点点教程,以便在我的Rails 4应用程序上安装和设置设计。

  2. Because we activated Devise's confirmable module, I need to send emails in development to allow users who signup to activate their account and login.

    因为我们激活了设计的可确认模块,所以我需要在开发中发送电子邮件,以允许注册的用户激活他们的帐户和登录。

  3. Whenever I create a new user (through http://localhost:3000/users/sign_up), I do get the following alert:

    每当我创建一个新用户(通过http://localhost:3000/users/sign_up)时,我都会得到以下警告:

A message with a confirmation link has been sent to your email address. Please follow the link to activate your account.

有确认链接的消息已经发送到您的电子邮件地址。请按照链接激活您的帐户。

  1. However, I never actually receive the email with the confirmation link.
  2. 但是,我从来没有收到过带有确认链接的邮件。

——————————

- - - - - - - - - - -

UPDATE

更新

In my development.log file, I can see that the email was "sent":

在我的发展。日志文件,我可以看到邮件是“发送”的:

Devise::Mailer#confirmation_instructions: processed outbound mail in 172.1ms

Sent mail to hello@mydomain.com (54.4ms)
Date: Tue, 25 Aug 2015 12:15:15 -0700
From: contact@anotherdomain.com
Reply-To: contact@anotherdomain.com
To: hello@mydomain.com
Message-ID: <55dcbec3a1ef8_33b93fcffc4988f493685@XXXXXX.local.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Welcome hello@mydomain.com!</p>

<p>You can confirm your account email through the link below:</p>

<p><a href="http://localhost:3000/users/confirmation?confirmation_token=ZsL_iQVxfDQd7mB1RkGf">Confirm my account</a></p>

  [1m[35m (0.8ms)[0m  commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 560ms (ActiveRecord: 1.7ms)

And, when I copy and paste the link from the log into my browser, then I get the following alert:

当我将日志中的链接复制粘贴到浏览器时,我得到以下警告:

Signed in successfully.

在成功地签署。

So, it seems the only thing that is not working is the actual sending / receiving of the email.

所以,看起来唯一不起作用的是电子邮件的实际发送/接收。

——————————

- - - - - - - - - - -

As recommended in the tutorial, I followed Rails documentation regarding ActionMailer configuration and here is what I have in my config/environments/development.rb file:

按照本教程的建议,我遵循了关于ActionMailer配置的Rails文档,这是我在配置/环境/开发中所拥有的。rb文件:

config.action_mailer.delivery_method = :sendmail
  # Defaults to:
  # config.action_mailer.sendmail_settings = {
  #   location: '/usr/sbin/sendmail',
  #   arguments: '-i -t'
  # }
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_options = {from: 'hello@mydomain.com'}
  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

Obviously, I am missing something, but I cannot figure out what (I am very, very junior with Rails).

显然,我错过了一些东西,但我不知道什么(我非常,非常年轻)。

Any idea?

任何想法?

2 个解决方案

#1


4  

Mail is not sent in development by default. To enable this you have to set config.action_mailer.perform_deliveries = true in development.rb file which I see you already have.

在开发中默认不发送邮件。要启用它,必须设置config.action_mailer。perform_delivery = true in development。rb文件,我看到你们已经有了。

You may also have to enable config.action_mailer.raise_delivery_errors = true to raise delivery errors. That way, you will be able to see if there are any errors in the email delivery process.

您可能还需要启用config.action_mailer。raise_delivery_errors = true以提高交付错误。这样,您就可以看到邮件发送过程中是否有错误。

Also, double check your default from if that has a valid email.

另外,再次检查你的默认设置是否有一个有效的电子邮件。

Also try switching the delivery method to sendmail:

也可以尝试将发送方式改为发送邮件:

config.action_mailer.delivery_method = :sendmail

This should solve your issue.

这应该能解决你的问题。

#2


0  

You need a mail server for Action Mailer to send emails. such as MailGun which has a free account and a gem which makes set up easy. mailgun_rails

您需要一个邮件服务器用于动作邮件发送器来发送电子邮件。比如MailGun,它有一个免费的账户和一个宝石,使建立起来很容易。mailgun_rails

#1


4  

Mail is not sent in development by default. To enable this you have to set config.action_mailer.perform_deliveries = true in development.rb file which I see you already have.

在开发中默认不发送邮件。要启用它,必须设置config.action_mailer。perform_delivery = true in development。rb文件,我看到你们已经有了。

You may also have to enable config.action_mailer.raise_delivery_errors = true to raise delivery errors. That way, you will be able to see if there are any errors in the email delivery process.

您可能还需要启用config.action_mailer。raise_delivery_errors = true以提高交付错误。这样,您就可以看到邮件发送过程中是否有错误。

Also, double check your default from if that has a valid email.

另外,再次检查你的默认设置是否有一个有效的电子邮件。

Also try switching the delivery method to sendmail:

也可以尝试将发送方式改为发送邮件:

config.action_mailer.delivery_method = :sendmail

This should solve your issue.

这应该能解决你的问题。

#2


0  

You need a mail server for Action Mailer to send emails. such as MailGun which has a free account and a gem which makes set up easy. mailgun_rails

您需要一个邮件服务器用于动作邮件发送器来发送电子邮件。比如MailGun,它有一个免费的账户和一个宝石,使建立起来很容易。mailgun_rails