使用 Action Mailer 在 Ruby 中解析电子邮件
我使用 net/pop 检索邮件,但我还需要解析电子邮件以从地址和电子邮件正文获取主题。 对 Action Mailer 有什么想法吗? 我应该使用第 3 方宝石。(不,甚至不是 Tmail)
require 'rubygems'
require 'net/pop'
require 'pop_ssl'
Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE)
def pull_mail
Net::POP3.start("pop.gmail.com", 995, "uname","pass") do |pop|
if pop.mails.empty?
puts 'No mails.'
else
pop.each_mail do |mail|
puts mail_header
end
end
end
干杯!
I retrieve mail using net/pop , but I also need to parse through the email to obtain subject,from address and email body.
Any ideas with Action Mailer?
I'm supposed to use 3rd party gems.(No,not even Tmail)
require 'rubygems'
require 'net/pop'
require 'pop_ssl'
Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE)
def pull_mail
Net::POP3.start("pop.gmail.com", 995, "uname","pass") do |pop|
if pop.mails.empty?
puts 'No mails.'
else
pop.each_mail do |mail|
puts mail_header
end
end
end
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,您只需要编写电子邮件处理程序,所有解析都会在幕后为您完成:
当您使用 Net::POP3 收到电子邮件时,只需将它们交给您的处理程序即可:
Basically, you just need to write your email handler, and all the parsing will be done for you behind the scenes:
When you get emails using Net::POP3, just hand them off to your handler: