繁体   English   中英

Rails邮件程序不发送电子邮件

[英]Rails mailer does not send email

当我尝试使用Rails(5.1.4)邮件程序时,没有收到应有的任何电子邮件。 我遵循了官方的Rails指南。 我的config / environment / development.rb:

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            'username@gmail.com',
    password:             'app-password-from-google',
    authentication:       'plain',
    enable_starttls_auto: true 
  }

通过此配置,我在mailers / appointement_mailer.rb中创建了一个新邮件:

class AppointementMailer < ApplicationMailer
  default :from => "username@gmail.com"

  def appointement_information(user_email, data)
    @email = user_email
    @body = data
    mail(:to => "username@gmail.com", :subject => "xxx")
  end
end

该邮件由控制器控制的表单触发,它位于controllers / contacts_controller.rb下:

      def new

      end

      def create
        @appointement = appointement_params
        AppointementMailer.appointement_information(@appointement['email'], @appointement['body'])
        flash[:notice] = "Some message"
        redirect_to articles_path
      end

      private
      def appointement_params
        params.require('appointement').permit(:email, :body)
      end

表单正确显示Flash“ Some Message”,并且控制台中未写入任何错误。

您需要在打给邮件程序的电话上调用deliver_now

AppointementMailer.appointement_information(@appointement['email'], @appointement['body']).deliver_now

暂无
暂无

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

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