【问题标题】:set REPLY-TO in email pony ruby在电子邮件小马红宝石中设置回复
【发布时间】:2020-05-27 15:40:12
【问题描述】:

我们的API 内置在Ruby 中,带有Sinatra gem。并使用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

shareshare_request 中的reply_to 根本不起作用.. 任何帮助将不胜感激。谢谢

【问题讨论】:

  • 触发一个可以从控制器为你完成工作的外部脚本。
  • 最好从您的应用使用的Gemfile.lock 文件中添加 Pony gem 和 Mail gem 的版本。
  • 我认为您尝试过一个更简单的案例,在独立程序中使用 Pony,并带有硬编码的回复参数?如果没有,我认为这将是一个很好的下一步。 (另外:也许我只是没有看到它,但是上面代码中的share 来自哪里?)
  • 我的意思是 sharer 不是 share...

标签: ruby sinatra pony


【解决方案1】:

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

选项列表

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

Pony.permissable_options

选项几乎直接传递给邮件

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-22
    • 1970-01-01
    • 2012-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    相关资源
    最近更新 更多