Sebastian Delgado
Sebastian Delgado

Reputation: 725

Is it possible to send emails from the current user email?

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: "[email protected]", to: "[email protected]"
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.

Upvotes: 0

Views: 507

Answers (1)

Sebastian Delgado
Sebastian Delgado

Reputation: 725

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

Upvotes: 1

Related Questions