简体   繁体   English

Ruby on Rails - 在生产中没有收到“欢迎电子邮件”

[英]Ruby on Rails - Not receiving 'Welcome Email' in Production

I'm attempting to send a welcome email when a new user is created via Action Mailer. 我正在尝试通过Action Mailer创建新用户时发送欢迎电子邮件。 I've followed the guide here: https://guides.rubyonrails.org/action_mailer_basics.html 我按照指南进行了操作: https//guides.rubyonrails.org/action_mailer_basics.html

The email is successful when creating a user on localhost:3000, but when I deploy and test in production environment (Heroku), no success. 在localhost:3000上创建用户时,电子邮件是成功的,但是当我在生产环境(Heroku)中部署和测试时,没有成功。

Even worse, I'm not seeing errors in the Heroku logs. 更糟糕的是,我没有看到Heroku日志中的错误。

I'm not really sure what to check at this point. 我不确定在这一点上要检查什么。 I've tried moving everything to my application.rb file since the configuration is the same (see: ActionMailer doesn't work in production ) 我已经尝试将所有内容移动到我的application.rb文件,因为配置是相同的(请参阅: ActionMailer在生产中不起作用

I thought that it may be sending a delayed message, but I've already tried UserMailer.with(user: @user).welcome_email.deliver_later as well as deliver_now 我认为它可能正在发送延迟消息,但我已经尝试过UserMailer.with(user: @user).welcome_email.deliver_later deliver_now以及deliver_now

config/application.rb 配置/ application.rb中

config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
      address:              'smtp.gmail.com',
      port:                 587,
      domain:               'gmail.com',
      user_name:            ENV["GMAIL_USERNAME"],
      password:             ENV["GMAIL_PASSWORD"],
      authentication:       'plain',
      enable_starttls_auto: true }

config/environments/production.rb 配置/环境/ production.rb

config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false

mailers/user_mailer 邮寄/ user_mailer文件

class UserMailer < ApplicationMailer
  default from: 'pickleballsocial@gmail.com'

  def welcome_email
    @user = params[:user]
    @url  = 'https://pickleballsocial.herokuapp.com'
    mail(to: @user.email, subject: 'Welcome Pickleball Social')
  end
end

users_controller users_controller

def create
    @user = User.new(user_params)

    respond_to do |format|
      if @user.save
        session[:user_id] = @user.id
        # Tell the UserMailer to send a welcome email after save
        UserMailer.with(user: @user).welcome_email.deliver_later

        format.html { redirect_to(@user, notice: 'User was successfully created.') }
        format.json { render json: @user, status: :created, location: @user }

        #redirect_to user_path(@user)
      else
        format.html { render action: 'new' }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end

I don't see any major issues with your code. 我没有看到您的代码有任何重大问题。 First thing I'd check is to make sure the credentials are correct. 我要检查的第一件事是确保凭据是正确的。 If that's not the issue, without log information, I'm not sure of the problem. 如果这不是问题,没有日志信息,我不确定问题。

From the guides 指南

Note: As of July 15, 2014, Google increased its security measures and now blocks attempts from apps it deems less secure. 注意:截至2014年7月15日,Google增加了其安全措施,现在阻止其认为不太安全的应用程序的尝试。 You can change your Gmail settings here to allow the attempts. 您可以在此处更改Gmail设置以允许尝试。 If your Gmail account has 2-factor authentication enabled, then you will need to set an app password and use that instead of your regular password. 如果您的Gmail帐户启用了双因素身份验证,那么您需要设置应用密码并使用该密码而不是常规密码。 Alternatively, you can use another ESP to send email by replacing 'smtp.gmail.com' above with the address of your provider. 或者,您可以使用另一个ESP通过将上面的'smtp.gmail.com'替换为您的提供商的地址来发送电子邮件。

Can you check your gmail security settings from that article link? 你能从那篇文章链接中查看你的Gmail安全设置吗? I'm wondering if the production host is blocked because it's coming from something that might seem less secure (a hosted server, versus your local computer) 我想知道生产主机是否被阻止,因为它来自可能看起来不太安全的东西(托管服务器,而不是本地计算机)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM