0

我们有API内置的 Ruby 和Sinatragem。并Pony用于发送电子邮件。我想设置参数reply-to。我已经尝试了所有可能性,即使是 Pony gem 文档所说的方式,但它根本不起作用..

我们的邮件代码是

require 'logjam'
require 'pony'

module Evercam
  module Mailers
    class Mailer
      LogJam.apply(self, "actors")

      @@templates = {}

      def initialize(inputs)
        @inputs = inputs
      end

      def erb(name)
        ERB.new(template(name)).result(binding)
      end

      private

      def template(name)
        @@templates[name] ||= File.read(
          File.expand_path(File.join('.', name))
        )
      end

      def method_missing(name)
        if @inputs.keys.include?(name)
          @inputs[name]
        end
      end

      def self.method_missing(name, *inputs)
        if self.method_defined?(name) && inputs[0]
          begin
            opts = self.new(inputs[0]).send(name)
            mail = Evercam::Config[:mail].merge(opts)
            Pony.mail(mail)
          rescue Exception => e
            log.warn(e)
          end
        end
      end

    end
  end
end

require_relative 'mailer'

module Evercam
  module Mailers
    class UserMailer < Mailer

      def confirm
        {
          to: user.email,
          subject: 'Evercam Confirmation',
          html_body: erb('templates/emails/user/confirm.html.erb'),
          body: erb('templates/emails/user/confirm.txt')
        }
      end

      def share
        {
          to: email,
          subject: "#{user.fullname} has shared a camera with you",
          html_body: erb('templates/emails/user/camera_shared_notification.html.erb'),
          attachments: attachments,
          reply_to: sharer
        }
      end

      def share_request
        {
          to: email,
          subject: "#{user.fullname} has shared a camera with you",
          html_body: erb('templates/emails/user/sign_up_to_share_email.html.erb'),
          attachments: attachments,
          reply_to: sharer
        }
      end

      def interested
        {
          to: 'signups@evercam.io',
          subject: 'Signup on evercam.io',
          body: erb('templates/emails/user/interested.txt')
        }
      end

      def app_idea
        {
          to: 'garrett@evercam.io',
          subject: 'Marketplace idea on evercam.io',
          body: erb('templates/emails/user/app_idea.txt')
        }
      end

      def create_success
        {
          to: archive.user.email,
          subject: "Archive #{archive.title} is ready.",
          html_body: erb('templates/emails/user/archive_create_completed.html.erb'),
          attachments: attachments
        }
      end

      def create_fail
        {
          to: archive.user.email,
          subject: "Archive #{archive.title} failed.",
          html_body: erb('archive_creation_failed.html.erb'),
          attachments: attachments
        }
      end
    end
  end
end

reply_to inshare和 inshare_request根本不起作用.. 任何帮助将不胜感激。谢谢

4

1 回答 1

1

这个问题似乎很老,但是当我问自己同样的问题时,我偶然发现了它。我终于回到了小马的 git 页面,在文档中找到了答案。

选项列表

您可以直接从 Pony 获取选项列表:

Pony.permissable_options

选项几乎直接传递给邮件

  • 附件#见附件部分
  • 密件抄送
  • body # 纯文本正文
  • body_part_header # 见自定义标题部分
  • 抄送
  • charset # 如果你需要发送 utf-8 或类似的
  • 内容类型
  • headers # 见自定义标题部分
  • html_body # 用于发送 html 格式的电子邮件
  • html_body_part_header # 见自定义标题部分
  • message_id
  • reply_to #这个好像就是我们要找的那个。尚未测试。
  • sender # 设置“信封来自”(和 Sender 标头)
  • smtp_envelope_to
  • 主题
  • text_part_charset # 对于多部分消息,设置文本部分的字符集
于 2020-05-27T07:40:12.483 回答