Need help reading letters with a "postal" ruby ​​gem

I am doing automation using Watir, which creates an email that I need to check. I was listed as a mailbox as the easiest way to do this.

I have added the following code and can receive the 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 ask the following questions:

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

  • How can I get all the links that are inside emails? Or the body of a mail message from a specific email? I need to receive the email of the first unread message.

  • How can I receive emails from a specific folder if I have subfolders inside my mailbox?

+6
source share
3 answers

Section 6.4.4 of the IMAP protocol specifies various search flags that you can use to search for messages.

You can only receive new messages by passing search flags to the find method like this:

 new_messages = Mail.find(keys: ['NOT','SEEN']) 

This post also answered a problem in the Mail GitHub repository .

+13
source

Looks like you read some of the documentation . Mail.all returns all emails, including read emails. Mail.first returns the first unread. I would suggest that this returns the next unread again. If your system is controlled, you don’t have to worry about the number of unread messages. If I were you, I would try it in IRB until you deal with it, maybe even create a class that will simplify your work. Good luck.

Update: documentation from the mailbox. If Mail.first does not return an unread email (all the time), the author should know. You can send a question. I myself do not use this stone. I am using gmail gem for testing.

 Mail.all #=> Returns an array of all emails Mail.first #=> Returns the first unread email Mail.last #=> Returns the first unread email 
+1
source

how about saving time when you read letters, and then the next time you read the mail of all mail letters only later than this date? I know itz workaround, but I believe that it is not supported by mail stone. Mailman gem supports this, but deletes mail after processing it.

0
source

Source: https://habr.com/ru/post/914155/


All Articles