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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With