2012-03-15 49 views
0
pop = Net::POP3.new mailhost 
    pop.start mailuser, mailpass 

    if pop.mails.empty? 

     puts "Mailbox empty." 

    else 

     pop.mails.each do |mail|  
     if mail.pop.has_attachments? 
      mail.pop.attachments.each do |attachment| 
       puts attachment.original_filename 
      end 
     end 
     end 

    end 

給出undefined method 'has_attachments?' for #<String:0xb7cc4f7c>如何使用ruby net/pop分離POP3的附件?

this example不再工作?

+0

嘿@ohho,你能得到這個工作?我正在做一些simlair,我可以做message.head,message.blah並知道試着將附件下載到本地目錄。 TIA。 – zee 2016-09-01 03:28:24

回答

1

mail.pop返回電子郵件的字符串表示形式請參見corresponding docs。如果要分析它,並與mail對象工作,你可以做這樣的:

email = Mail.new(mail.pop) 

我真的建議你看看到文檔 - 如果你有大的附件,你可以遇到內存問題,這個東西在文檔中解釋。