0
votes

Question: How do I set up my mailer/devise to allow the "from" to be from the current_user.email versus just one email?

Explanation: I have connected my rails mailer to use 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. 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. "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"

    def confirmation_instructions(record, token, opts={})
      headers["Custom-header"] = "Bar"
      opts[:from] = '[email protected]'
      opts[:reply_to] = '[email protected]'
      super
    end

I am jr developer and haven't worked much with changing mailer settings. This is my mailer. My controller is bringing the current_user over, and is logging correctly.

    class FeedbackMailer < ActionMailer::Base
        default to: "[email protected]"

        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: "[email protected]", subject: 
     "You have Feedback")

        end 
    end
1

1 Answers

0
votes

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."


1) Rails: change default sender in action mailer

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

hope this helps someone!