Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 是否可以从当前用户的电子邮件发送电子邮件?_Ruby On Rails_Ruby_Email_Smtp_Actionmailer - Fatal编程技术网

Ruby on rails 是否可以从当前用户的电子邮件发送电子邮件?

Ruby on rails 是否可以从当前用户的电子邮件发送电子邮件?,ruby-on-rails,ruby,email,smtp,actionmailer,Ruby On Rails,Ruby,Email,Smtp,Actionmailer,我正在为一家公司开发一名内部运营经理,他们需要自动向客户发送电子邮件,但电子邮件必须通过负责该特定客户的公司运营商的电子邮件地址发送 因此,基本上,我需要配置我的邮件程序,以处理N封不同的电子邮件,我也可以访问他们的电子邮件密码 config.action_mailer.smtp_settings = { :address => 'smtp.office365.com', :port => '587', :authenti

我正在为一家公司开发一名内部运营经理,他们需要自动向客户发送电子邮件,但电子邮件必须通过负责该特定客户的公司运营商的电子邮件地址发送

因此,基本上,我需要配置我的邮件程序,以处理N封不同的电子邮件,我也可以访问他们的电子邮件密码

  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
  }
我发现可以通过以下方式将电子邮件地址发送到mailer配置:

def new_mail
  mail from: "example@example.com", to: "user@example.com"
end
P>但是密码是什么呢?这是通过Rails还是可能的,或者我应该考虑其他工具,比如MailGun?< /P>
非常感谢您花点时间阅读本文。

显然,您可以发送带有用户名、主机和密码的delivery_options对象

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

我会选择mailgun,因为它是一个不那么脆弱和简单的解决方案。它将从默认设置发送邮件,但如果我们设置发件人,则它将在收件人邮件中显示发件人邮件id。太酷了。。