【问题标题】:How to fetch "Reply-To" attribute from email by using mailman (Rails)?如何使用 mailman (Rails) 从电子邮件中获取“回复”属性?
【发布时间】:2016-03-03 22:54:22
【问题描述】:

我正在使用 Mailman gem 从我的 rails 应用程序中轮询电子邮件。我关注了 Railcasts here

在那篇 Railscasts 中,Ryan Bates 展示了如何从我们收到的电子邮件中检索主题和内容,我可以照着做。

但是现在,我想从电子邮件中获取另一个属性,更具体地说是 “Reply-To” 属性。那我该怎么做呢?

我试过这样做:message.Reply-to,但我得到了

undefined method `Reply' for #<Mail::Message:0x007fc0fd641890> (NoMethodError) 

当我尝试测试它时。以下是完整错误信息的截图:

下面是我的 mailman_server 文件:

#!/usr/bin/env ruby
require "rubygems"
require "bundler/setup"
require "mailman"

#Mailman.config.logger = Logger.new("log/mailman.log")

Mailman.config.pop3 = {
  server: 'pop.gmail.com', port: 995, ssl: true,
  username: "xxxxx@gmail.com",
  password: "xxxxx"
}

Mailman::Application.run do
  default do
    puts "Received: #{message.Reply-To}"
  end
end

下面是我的 mailman_test.eml 文件:

Date: Fri, 25 February 2016
From: myappsender@gmail.com
Subject: Mailman Test
To: myappsupport@gmail.com
Reply-To: myappreply@gmail.com

【问题讨论】:

  • define: '不工作'
  • @Ecnalyr 我得到了 <:message:0x007fc0fd641890> 的 undefined method Reply' (NoMethodError)`
  • 你试过按键访问吗?显然Reply-To 不是有效的Ruby 符号。或者,API 可能有一种访问标头的方法。

标签: ruby-on-rails ruby email ruby-on-rails-4 mailman


【解决方案1】:

mailman gem 在处理传入邮件时在内部使用Mail::Message

所以你可以使用Mail::Message 的所有方法供你使用。其中一种方法是reply_to。所以你可以试试message.reply_to

请参阅Mail::Message Documentation 了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    • 2012-02-09
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多