尽管收到了成功通知,但在heroku生产环境中没有收到电子邮件



当我在本地主机中运行"rails s"并发送电子邮件时,我收到一个通知,"您的名字已通过电子邮件发送",并在终端中看到它似乎已经工作了。一切都好!

但当我将其部署到heroku并发送电子邮件时,我收到了一个通知,"你的名字已通过电子邮件发送",但从未收到我真正收件箱中的电子邮件。你知道我为什么没有收到邮件吗?

我已经为用户身份验证系统设置了电子邮件,并在heroku上进行了实时测试,当我注册用户时,我通过这个应用程序收到了发送到我真实收件箱的电子邮件,所以我相信配置设置是正确的。

这把我逼疯了!感谢任何帮助:D

终端:

Started PUT "/profiles/1/email" for 127.0.0.1 at 2014-10-06 14:45:51 +1100
Processing by ProfilesController#email as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"j7RcI5ec+Uckt5mt6Z0m5iD/KvnoWn/GXNzmHMxOjgg=", "name"=>"Scott", "destination"=>"sdasd@gmail.com", "commit"=>"Send Email", "id"=>"1"}
  User Load (0.2ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
  CACHE (0.0ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = ? LIMIT 1  [["id", "1"]]
  Profile Load (0.1ms)  SELECT  "profiles".* FROM "profiles"  WHERE "profiles"."user_id" = ? LIMIT 1  [["user_id", 1]]
  Rendered user_mailer/profile.html.erb (0.1ms)
  Rendered user_mailer/profile.text.erb (0.1ms)
UserMailer#profile: processed outbound mail in 9.3ms
Sent mail to destination (5.5ms)
Date: Mon, 06 Oct 2014 14:45:51 +1100
From: noreply@example.com
To: destination
Message-ID: <5432106f1d6ef_12a33fec3247b7d410068e@S-MacBook-Pro.local.mail>
Subject: Lorem Ipsum bum Lorem Ipsum has shared their name with you
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="--==_mimepart_5432106f1c926_12a33fec3247b7d41005c2";
 charset=UTF-8
Content-Transfer-Encoding: 7bit

----==_mimepart_5432106f1c926_12a33fec3247b7d41005c2
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Hi Scott,
Lorem Ipsum bum Lorem Ipsum sent you their name:
First Name: Lorem Ipsum bum

Kind Regards,
Lorem Ipsum bum Lorem Ipsum
----==_mimepart_5432106f1c926_12a33fec3247b7d41005c2
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
<p>Hi Scott,</p>
<p>Lorem Ipsum bum Lorem Ipsum sent you their name:</p>
<li><strong>First Name:</strong>Lorem Ipsum bum</li>
<p>Kind Regards,<br />
Lorem Ipsum bum Lorem Ipsum</p>
----==_mimepart_5432106f1c926_12a33fec3247b7d41005c2--
Redirected to http://localhost:3000/users/1
Completed 302 Found in 21ms (ActiveRecord: 0.3ms)

Started GET "/users/1" for 127.0.0.1 at 2014-10-06 14:45:51 +1100
Processing by UsersController#show as HTML
  Parameters: {"id"=>"1"}
  User Load (0.1ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = ? LIMIT 1  [["id", 1]]
  Profile Load (0.0ms)  SELECT  "profiles".* FROM "profiles"  WHERE "profiles"."user_id" = ? LIMIT 1  [["user_id", 1]]
  Rendered profiles/_profile.html.erb (0.3ms)
  Rendered users/show.html.erb within layouts/application (1.3ms)
  Rendered layouts/_shim.html.erb (0.1ms)
  User Load (0.1ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1 LIMIT 1
  Rendered layouts/_header.html.erb (1.0ms)
  Rendered layouts/_footer.html.erb (0.1ms)
Completed 200 OK in 97ms (Views: 95.7ms | ActiveRecord: 0.2ms)

配置文件控制器:

def email
    @user = User.find(params[:id])
    destination = params[:to]
    name = params[:name]
    user = User.find(params[:id])
    user_mailer = UserMailer.profile(@profile, destination, name, user)
    if user_mailer.deliver
      flash[:success] = "Your name was emailed"
      redirect_to @user
    else
      flash[:danger] = "Your name could not be emailed"
      redirect_to @user
    end
  end

环境/生产:

# Sendgrid config
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  host = 'example.herokuapp.com'
  config.action_mailer.default_url_options = { host: host }
  ActionMailer::Base.smtp_settings = {
    :address        => 'smtp.sendgrid.net',
    :port           => '587',
    :authentication => :plain,
    :user_name      => ENV['SENDGRID_USERNAME'],
    :password       => ENV['SENDGRID_PASSWORD'],
    :domain         => 'heroku.com',
    :enable_starttls_auto => true
  }

如果这有助于以下是一些与用户激活相关的信息,以显示其他电子邮件是如何在应用程序中设置的(当在heroku/gmail上测试时,这些电子邮件在现实生活中有效)

用户控制器:

def create
    @user = User.new(user_params)
    if @user.save
      @user.profile = Profile.new
      @user.send_activation_email
      flash[:info] = "Please check your email to activate your account."
      redirect_to root_url
    else
      render 'new'
    end
  end

模块/用户:

  # Sends activation email.
  def send_activation_email
    UserMailer.account_activation(self).deliver
  end

。。。所以……事实证明,我在开发环境中根本没有正确发送它!:s电子邮件说它已经发送了,并且在终端中"发送"了,但它没有按照应该的方式传递目的地变量,所以它没有有效的发送电子邮件的地方。(终端将其传递给"destination"而不是"example@example.com我没有好好检查)。我修正了视图以正确地传递变量,瞧!

最新更新