【问题标题】:Is it possible to send emails from the current user email?是否可以从当前用户电子邮件发送电子邮件?
【发布时间】:2018-09-15 18:20:26
【问题描述】:

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

所以基本上,我需要配置我的邮件程序来处理 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
  }

我已经看到可以通过这种方式将电子邮件地址发送到邮件配置:

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

但是密码呢?,这甚至可以通过 Rails 实现还是我应该考虑使用 MailGun 等其他工具?

非常感谢您花时间阅读本文。

【问题讨论】:

  • 我会选择 mailgun,因为它是一种不那么脆弱和更简单的解决方案。
  • 在这种情况下使用 sendgrid。它将默认发送邮件,但如果我们设置发件人,那么它将在接收者邮件中显示发件人邮件 ID。它超级酷..

标签: ruby-on-rails ruby email smtp actionmailer


【解决方案1】:

显然你可以发送一个包含用户名、主机和密码的 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

【讨论】:

    猜你喜欢
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 2019-07-04
    • 2021-04-15
    • 2020-01-14
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多