在邮件中设置REPLAY-TO,小马红宝石。

问题描述 投票:0回答:1

我们有我们 API 在Ruby中用 Sinatra 创业板,并使用 Pony 来发送邮件。我想设置参数 reply-to......我已经尝试了所有的可能性,甚至是Pony gem docs说的方式,但它根本就没有工作。

我们的邮件代码是

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: '[email protected]',
          subject: 'Signup on evercam.io',
          body: erb('templates/emails/user/interested.txt')
        }
      end

      def app_idea
        {
          to: '[email protected]',
          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。share 并在 share_request 是在所有工作......任何帮助将被感激。 谢谢

ruby sinatra pony
1个回答
1
投票

这个问题似乎很老了,但我在问自己同样的问题时偶然发现了这个问题。文件.

选项列表

你可以直接从Pony那里得到一个选项列表。

Pony.permissable_options

选项几乎直接传给了Mail

  • 附件 # 见附件部分
  • bcc
  • body #纯文本正文
  • body_part_header # 参见自定义标题部分。
  • cc
  • charset # 以防你需要发送utf-8或类似的格式。
  • 内容类型
  • 页眉 # 见自定义页眉部分
  • html_body # 用于发送html格式的电子邮件。
  • html_body_part_header # 参见自定义标题部分。
  • 信息_id
  • 回复 #这一个似乎是一个我们正在寻找, 尚未测试。
  • sender # 设置 "信封发件人"(和发件人头)
  • smtp_envelope_to
  • 课题
  • text_part_charset # 对于多部分信息,设置文本部分的字符集。
© www.soinside.com 2019 - 2024. All rights reserved.