使用“邮件”阅读电子邮件需要帮助宝石在红宝石 [英] Need help on reading emails with "mail" gem in ruby
问题描述
我添加了以下代码,并可以从我的收件箱获取第一封电子邮件。
require'mail'
require'openssl'
Mail.defaults do
retriever_method: pop3,:address => email.someemail.com,
:port => 995,
:user_name => 'domain / username',
:password => 'pwd',
:enable_ssl => true
end
put Mail.first
我是新的到这个论坛,并有以下问题:
-
如何获取所有未读电子邮件?我试过
Mail.all
,Mail.first
,Mail.last
,但没有返回未读电子邮件。 -
如何获取电子邮件中存在的所有链接?或邮件正文从特定的电子邮件?我需要收到第一个未读电子邮件的电子邮件正文。
-
如果我的收件箱中有子文件夹,我如何从特定的文件夹获取电子邮件? p>
您可以通过将搜索标记传递给find方法来检索新消息,如下所示:
new_messages = Mail.find(keys :['NOT','SEEN'])
此消息也在 Mail on GitHub repo 。
I am doing automation using Watir that creates an email that I need to check. I was pointed at the email gem as being the easiest way to do this.
I added following code and am able to get first email from my inbox.
require 'mail'
require 'openssl'
Mail.defaults do
retriever_method :pop3, :address => "email.someemail.com",
:port => 995,
:user_name => 'domain/username',
:password => 'pwd',
:enable_ssl => true
end
puts Mail.first
I am new to this forum and have following questions :
How can I get all the unread emails? I tried
Mail.all
,Mail.first
,Mail.last
, but nothing returns unread email.How can I get all links that are present inside emails? Or mail message body from the specific email? I need to get the email body of first unread email.
How can I get emails from a specific folder, if I have subfolders inside my inbox?
Section 6.4.4 of the IMAP protocol indicates the different search flags you can use to search for messages.
You can retrieve only new messages by passing the search flags to the find method like so:
new_messages = Mail.find(keys: ['NOT','SEEN'])
This message was also answered in an issue on the Mail GitHub repo.
这篇关于使用“邮件”阅读电子邮件需要帮助宝石在红宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!