Ruby on rails 邮件默认为

Ruby on rails 邮件默认为,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我有一个管理员电子邮件: class AdminMailer < ApplicationMailer ADMIN_EMAIL = 'admin@gmail.com' def send1 mail(to: ADMIN_EMAIL, subject: 'You have a new registered user') end end class AdminMailer

我有一个管理员电子邮件:

class AdminMailer < ApplicationMailer
  ADMIN_EMAIL = 'admin@gmail.com'

  def send1
    mail(to: ADMIN_EMAIL, subject: 'You have a new registered user')
  end

end
class AdminMailer
由于它是一个管理员电子邮件程序,我想知道,是否有可能让mail在默认情况下将电子邮件发送给管理员?比如:

class AdminMailer < ApplicationMailer
  default to: 'admin@gmail.com'
class AdminMailer

我从未见过选项
to
,它存在吗?

是的,默认值可以设置为
:to
参数

从rails代码库的相关部分
#可以为上述任何标题设置默认值(除了+:date+

请参阅上的代码注释

#创建邮件和呈现电子邮件模板的主要方法。有
#调用此方法的两种方法,带块或不带块。
#
#它接受头散列。此哈希允许您指定
#电子邮件中最常用的标题如下:
#
#*+:主题+-消息的主题,如果省略,则Action Mailer将
#要求Rails I18n类在
#[mailer\u范围、操作\u名称]或如果缺少,将转换
#+action\u名称的人性化版本+
#*+:收件人+-邮件的目的地,可以是一个地址字符串,也可以是一个数组
#地址。
#*+:来自+-消息来自谁
#*+:cc+-您想在这封电子邮件上抄写的人,可以是一组地址,
#或地址数组。
#*+:密件抄送+-您想在这封电子邮件上盲抄送的人可以是一串
#地址,或地址数组。
#*+:reply_to+-将电子邮件的回复标题设置为谁。
#*+:date+-表示发送电子邮件的日期。
#
#您可以为上述任何标题设置默认值(除了+:日期+)
#通过使用::default类方法:
#
#类通知程序
# The main method that creates the message and renders the email templates. There are
# two ways to call this method, with a block, or without a block.
#
# It accepts a headers hash. This hash allows you to specify
# the most used headers in an email message, these are:
#
# * +:subject+ - The subject of the message, if this is omitted, Action Mailer will
#   ask the Rails I18n class for a translated +:subject+ in the scope of
#   <tt>[mailer_scope, action_name]</tt> or if this is missing, will translate the
#   humanized version of the +action_name+
# * +:to+ - Who the message is destined for, can be a string of addresses, or an array
#   of addresses.
# * +:from+ - Who the message is from
# * +:cc+ - Who you would like to Carbon-Copy on this email, can be a string of addresses,
#   or an array of addresses.
# * +:bcc+ - Who you would like to Blind-Carbon-Copy on this email, can be a string of
#   addresses, or an array of addresses.
# * +:reply_to+ - Who to set the Reply-To header of the email to.
# * +:date+ - The date to say the email was sent on.
#
# You can set default values for any of the above headers (except +:date+)
# by using the ::default class method:
#
#  class Notifier < ActionMailer::Base
#    default from: 'no-reply@test.lindsaar.net',
#            bcc: 'email_logger@test.lindsaar.net',
#            reply_to: 'bounces@test.lindsaar.net'
#  end