简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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