简体   繁体   English

使用Devise配置ActionMailer以允许电子邮件来自其他用户。

[英]Configure ActionMailer with Devise to allow email to come from different user.

Question: How do I set up my mailer/devise to allow the "from" to be from the current_user.email versus just one email? 问题:如何设置邮件收发器/设备以允许“发件人”来自current_user.email,而不是一封电子邮件?

Explanation: I have connected my rails mailer to use Microsoft exchange. 说明:我已连接Rails邮件程序以使用Microsoft Exchange。 Everything is working fine, but the issue I am running into is who the "from" in the emails (development.rb, mailer, and devise.rb) has to be the same in order for the emails to go out. 一切工作正常,但是我遇到的问题是电子邮件(development.rb,mailer和devise.rb)中的“发件人”必须相同,以便电子邮件出去。 Our application has different admin users, and we would like the outgoing emails to come from their email versus just one. 我们的应用程序有不同的管理员用户,我们希望传出的电子邮件来自他们的电子邮件,而不是一个。

this is the link I followed for setting up microsoft exchage. 这是我用来设置Microsoft Exchage的链接。 " https://www.brownwebdesign.com/blog/connecting-rails-to-microsoft-exchange-smtp-email-server " https://www.brownwebdesign.com/blog/connecting-rails-to-microsoft-exchange-smtp-email-server

I have tried using Devise Doc to set-up a mailer to specify my FROM, but still doesn't work.. " https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailer " 我一直在使用设计文件,以建立一个邮件到指定我从试过,但还是不行。“ 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

I am jr developer and haven't worked much with changing mailer settings. 我是jr开发人员,在更改邮件程序设置方面工作不多。 This is my mailer. 这是我的邮件。 My controller is bringing the current_user over, and is logging correctly. 我的控制器正在引导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

I found my answer in another post after changing my search many times... 在多次更改搜索后,我在另一篇文章中找到了答案...
"Most SMTP providers (Gmail, etc.) won't let you send an email from an address other than the address associated with the account that you are logging in to the SMTP server with, which in your case is probably the default from address configured in your app. If you think about it, that makes a lot of sense for security/SPAM protection. Would you want anyone to be able to send an email that showed your email address as the from address? I sure wouldn't. An alternative is to use :reply_to. When you hit reply in your email program it should use this if it's present." “大多数SMTP提供程序(Gmail等)都不允许您从与登录SMTP服务器所使用的帐户关联的地址以外的地址发送电子邮件,在您的情况下,这可能是默认的发自地址如果您考虑过这一点,那么考虑一下这对安全性/ SPAM保护非常有意义,您是否希望任何人都能够发送一封将您的电子邮件地址显示为发件人地址的电子邮件,我肯定不会。一种替代方法是使用:reply_to。当您在电子邮件程序中点击“ reply”时,应该使用它。


1) Rails: change default sender in action mailer 1) Rails:在行动邮件中更改默认发件人

2) Rails 3.2, how to change :from value in a mailer instead default (GMail) 2) Rails 3.2,如何更改:from邮件中的值,而不是默认值(GMail)

hope this helps someone! 希望这对某人有帮助!

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

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