使用“邮件”阅读电子邮件需要帮助宝石在红宝石 [英] Need help on reading emails with "mail" gem in ruby

查看:244
本文介绍了使用“邮件”阅读电子邮件需要帮助宝石在红宝石的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做自动化,使用Watir创建一个我需要检查的电子邮件。我指出电子邮件宝石是最简单的方法。



我添加了以下代码,并可以从我的收件箱获取第一封电子邮件。

  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

我是新的到这个论坛,并有以下问题:


  1. 如何获取所有未读电子邮件?我试过 Mail.all Mail.first Mail.last ,但没有返回未读电子邮件。


  2. 如何获取电子邮件中存在的所有链接?或邮件正文从特定的电子邮件?我需要收到第一个未读电子邮件的电子邮件正文。


  3. 如果我的收件箱中有子文件夹,我如何从特定的文件夹获取电子邮件? p>



解决方案

部分6.4.4表示您可以使用不同的搜索标记来搜索邮件。



您可以通过将搜索标记传递给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 :

  1. How can I get all the unread emails? I tried Mail.all, Mail.first, Mail.last, but nothing returns unread email.

  2. 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.

  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆