0

I'm developing an internal operations manager for a company, They need to send automatic emails to their costumers, but the email has to be sent by the email address of the company operator that is taking care of that specific costumer.

So basically, I need to configure my mailer to work with N different emails (I have access to their emails passwords too).

  config.action_mailer.smtp_settings = {
    :address        => 'smtp.office365.com',
    :port           => '587',
    :authentication => :login,
    :user_name      => ENV['SMTP_USERNAME'],
    :password       => ENV['SMTP_PASSWORD'],
    :domain         => 'interworldfreight.com',
    :enable_starttls_auto => true
  }

I've seen that it is possible to send the email address to the mailer config this way:

def new_mail
  mail from: "example@example.com", to: "user@example.com"
end

But what about the password?, is this even possible through only rails or should I consider other tool like MailGun ?

Thanks a lot for taking a moment to read this.

Ken White
  • 123,280
  • 14
  • 225
  • 444
Sebastian Delgado
  • 706
  • 3
  • 7
  • 26

1 Answers1

1

Apparently you can send a delivery_options object with the username, host and password.

class FclExwOperationMailer < ApplicationMailer

    def info_request (representative, shipper)
      @representative = representative
      @shipper  = shipper
      delivery_options = { user_name: representative.smtp_user,
                           password: representative.smtp_password,
                           address: representative.smtp_host }
      mail(to: shipper.email,
           subject: "Please see the Terms and Conditions attached",
           delivery_method_options: delivery_options)
    end

end
Sebastian Delgado
  • 706
  • 3
  • 7
  • 26