作者:许晓慧 | 来源:互联网 | 2023-05-17 17:24
Imattemptingtoextracttheattachmentsofemailssentfromoneofourserviceprovidersandsave
I'm attempting to extract the attachments of emails sent from one of our service providers and save them to a networked drive in order to display the information of a Smashing Dashboard.
我正在尝试提取从我们的某个服务提供商发送的电子邮件附件,并将其保存到网络驱动器,以显示Smashing Dashboard的信息。
I am attempting to use the Mail Gem to do this : https://github.com/mikel/mail http://www.rubydoc.info/github/mikel/mail/Mail
我正在尝试使用Mail Gem来执行此操作:https://github.com/mikel/mail http://www.rubydoc.info/github/mikel/mail/Mail
However I'm woefully inexperienced with ruby and especially this specific gem so I'm running into to errors deciphering the emails.
然而,我对ruby特别缺乏经验,特别是这个特定的宝石,所以我遇到了解密电子邮件的错误。
###########################################################################
######################## Connect to the POP Server ########################
###########################################################################
require 'mail'
Mail.defaults do
retriever_method :pop3, :address => "pop.gmail.com",
:port => 995,
:user_name => '----',
:password => '----',
:enable_ssl => true
end
###################################################################
######################## Retrieve the Mail ########################
###################################################################
email = Mail.first #=> Returns the first unread
puts email
if (email.length > 0)
puts "New Mail Found"
else
puts "No New Mail"
end
When I run this when there are no new emails everything runs fine, however when there is a new email I get the following error.
当我在没有新电子邮件的情况下运行时,一切运行正常,但是当有新电子邮件时,我收到以下错误。
/var/lib/gems/2.3.0/gems/mail-2.6.6/lib/mail/message.rb:1379
:in
method_missing
: undefined method length
for
method_missing:未定义的方法长度
# (NoMethodError) from Pop.rb:35:in main
来自Pop.rb的#(NoMethodError):35:在main中
This line corrosponds to the if statement. However the github examples very clearly use mail.length to check the number of emails returned and I just have no idea how to go about fixing this.
这一行与if语句相矛盾。然而,github示例非常清楚地使用mail.length来检查返回的电子邮件的数量,我只是不知道如何解决这个问题。
I'd be grateful of additional eyes checking this for anything obviously wrong, or even some tips to debug it.
我会感激额外的眼睛检查这个显然是错误的,甚至一些调试它的技巧。
1 个解决方案