使用Action Mailer在Ruby中解析电子邮件

使用Action Mailer在Ruby中解析电子邮件,ruby,email,parsing,action,mailer,Ruby,Email,Parsing,Action,Mailer,我使用net/pop检索邮件,但我还需要通过电子邮件解析,从地址和电子邮件正文中获取主题。 对Action Mailer有什么想法吗? 我应该使用第三方gems。(不,甚至不是Tmail) 干杯 基本上,您只需编写电子邮件处理程序,所有解析都将在幕后为您完成: class MailHandler < ActionMailer::Base def receive(email) # here you will have an email object and will be abl

我使用net/pop检索邮件,但我还需要通过电子邮件解析,从地址和电子邮件正文中获取主题。 对Action Mailer有什么想法吗? 我应该使用第三方gems。(不,甚至不是Tmail)


干杯

基本上,您只需编写电子邮件处理程序,所有解析都将在幕后为您完成:

class MailHandler < ActionMailer::Base
  def receive(email)
    # here you will have an email object and will be able to call methods like
    # email.subject and email.attachments

    puts "from: #{email.from}, subject: '#{email.subject}'"
  end
end

基本上,您只需编写电子邮件处理程序,所有解析都将在幕后为您完成:

class MailHandler < ActionMailer::Base
  def receive(email)
    # here you will have an email object and will be able to call methods like
    # email.subject and email.attachments

    puts "from: #{email.from}, subject: '#{email.subject}'"
  end
end
Net::POP3.start(server, port, username, password) do |pop|
  pop.each_mail { |mail| MailHandler.receive(mail.pop) }
end