【问题标题】:Configure ActionMailer with Devise to allow email to come from different user.使用 Devise 配置 ActionMailer 以允许来自不同用户的电子邮件。
【发布时间】:2025-12-28 08:10:06
【问题描述】:

问题:如何设置我的邮件程序/设计以允许“发件人”来自 current_user.email 而不是仅一封电子邮件?

说明:我已连接我的 rails 邮件程序以使用 Microsoft Exchange。一切正常,但我遇到的问题是电子邮件(development.rb、mailer 和 devise.rb)中的“发件人”必须相同才能使电子邮件发出。 我们的应用程序有不同的管理员用户,我们希望传出的电子邮件来自他们的电子邮件,而不是只有一个。

这是我设置 microsoft exchage 所遵循的链接。 "https://www.brownwebdesign.com/blog/connecting-rails-to-microsoft-exchange-smtp-email-server"

我已尝试使用 Devise Doc 设置邮件程序来指定我的 FROM,但仍然无法正常工作.. "https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer"

    def confirmation_instructions(record, token, opts={})
      headers["Custom-header"] = "Bar"
      opts[:from] = 'my_custom_from@domain.com'
      opts[:reply_to] = 'my_custom_from@domain.com'
      super
    end

我是初级开发人员,在更改邮件设置方面工作不多。 这是我的邮件。我的控制器将 current_user 带过来,并且记录正确。

    class FeedbackMailer < ActionMailer::Base
        default to: "JohnDoe@gmail.com"

        def question_email(email, type, notes, current_user)
            @user_email = current_user.email
            logger.debug("Are you getting the email or what? # . 
  {@user_email.inspect}")
            logger.debug("LOOKING FOR THE EMAIL #{email}")
            @email = email
            @type = type
            @notes = notes

            mail( from: "xxx@microsoft.com", subject: 
     "You have Feedback")

        end 
    end

【问题讨论】:

    标签: ruby-on-rails devise actionmailer


    【解决方案1】:

    多次更改搜索后,我在另一篇帖子中找到了答案...
    “大多数 SMTP 提供商(Gmail 等)不允许您从与您登录到 SMTP 服务器的帐户关联的地址以外的地址发送电子邮件,在您的情况下,这可能是默认的发件人地址在您的应用程序中配置。如果您考虑一下,这对于安全/垃圾邮件保护很有意义。您是否希望任何人都能够发送一封将您的电子邮件地址显示为发件人地址的电子邮件?我当然不会。另一种方法是使用 :reply_to。当您在电子邮件程序中点击回复时,如果它存在,它应该使用它。"


    1)Rails: change default sender in action mailer

    2) Rails 3.2, how to change :from value in a mailer instead default (GMail)

    希望这对某人有所帮助!

    【讨论】:

      最近更新 更多