ArgumentError SMTP To地址不能为空

问题描述

我收到ArgumentError SMTP“发送至”可能不是为测试创建的邮件程序中的空白。

我的代码与《 Rails指南》中的示例几乎相同,您可以在这里找到: https://guides.rubyonrails.org/action_mailer_basics.html

或Ruby on Rails教程: https://3rd-edition.railstutorial.org/book/account_activation_password_reset#sec-account_activation_mailer

服务器日志

Error performing ActionMailer::MailDeliveryJob (Job ID: fa1eac9b-a2e0-4b4b-aca7-c785141fd7ce) from Async(mailers) in 214.6ms: ArgumentError (SMTP To address may not be blank: []):

我的代码

  # Ignore bad email addresses and do not raise email delivery errors.
  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  host = 'sendish.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
  }

# app/mailers/appliction_mailer.rb
class ApplicationMailer < ActionMailer::Base
  default from: 'from@example.com'
  layout 'mailer'
end

# app/mailer/user_mailer.rb
class UserMailer < ApplicationMailer
  default from: 'notifications@example.com'

  def welcome_email(user)
    @user = user
    @url  = 'http://example.com/login'
    attachments.inline['helloworld.gif'] = File.read(Rails.root + 'public/helloworld.gif')
    mail to: user.email,subject: 'Welcome to My Awesome Site'
  end
end

# app/controllers/users_controller.rb
  # POST /users.json
  def create
    @user = User.new(user_params)

    respond_to do |format|
      if @user.save
        # Tell the UserMailer to send a welcome email after save
        UserMailer.welcome_email(@user).deliver_now

        format.html { redirect_to @user,notice: 'User was successfully created.' }
        format.json { render :show,status: :created,location: @user }
      else
        format.html { render :new }
        format.json { render json: @user.errors,status: :unprocessable_entity }
      end
    end
  end

    def user_params
      params.require(:user).permit(:name,:email,:login)
    end

我看到Mailer在我的开发中正在传递地址

UserMailer#welcome_email: processed outbound mail in 26.0ms
Date: Thu,10 Sep 2020 15:01:52 -0700
From: notifications@example.com
To: user@example.com
Subject: Welcome to My Awesome Site

其他信息

问题在Heroku生产中发生

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...