How to get list of folders via POP3 - ruby-on-rails

I'm using POP3 to fetch emails from gmail, I want to fetch a list of folders present in my gmail account but not finding a way of doing it. In IMAP there's a method list("","*") through which we can fetch the folders and then by using select("folder_name") we could fetch the emails.
How to fetch the list of folders via POP3. Please help. Thanks.

POP3 does not have the concept of folders. It is a very old mail protocol. There is only the Inbox. If you ever see folders on a POP3 client (like in outlook), that is a client side implementation. There are no folders on a POP3 server.
If you need access to the Gmail folders, you need to use IMAP.
hth,
Dave

Related

Rails 6 Action Mailbox and Gmail Integration How To

Rails 6 comes with Action Mailbox now. The documentation and community do not have great resources on how to integrate various services outside of the most common such as SendGrid.
Assuming a person uses Google's Gsuite Gmail:
How could they integrate that with Action Mailbox?
Would one use Gmail's API, or would that not be appropriate for Action Mailbox?
If Gmail doesn't work, what is different about SendGrid that makes it integrate appropriately?
Action Mailbox is built around receiving email from a Mail Transfer Agent (MTA) in real time, not periodically fetching email from a mailbox. That is, it receives mail sent via SMTP, it doesn't fetch mail (using IMAP or POP3) from another server that has already received it.
For this to work it is dependent on an external (to Rails) SMTP service receiving the email and then delivering the email to Action Mailbox. These external services are called "Ingresses" and, as at the time of writing, there are 5 available ingresses.
Of the five, four are commercial services that will run the required SMTP servers for you and then "deliver" the email to your application (usually as a JSON payload via a webhook).
Mailgun - scroll down to "Inbound"
Mandrill
Postmark
Sendgrid
You could already use those services in a Rails App and handle the webhooks yourself but Action Mailbox builds a standardised set of functionality on top. Almost like a set of rails to guide and speed the process.
In addition, the fifth ingress is the "Relay" ingress. This allows you to run your own supported MTA (SMTP server) on the same machine and for it to relay the received email to Action Mailbox (usually the raw email). The currently supported MTAs are:
Exim
Postfix
Qmail
To answer your specific questions about Gmail:
How could they integrate that with Action Mailbox?
They couldn't directly. They would need to also set up one of the 7 MTAs listed above and then somehow deliver the emails to that. The delivery could be accomplished with:
Forwarding rules managed by the user at the mailbox level
Dual delivery, split delivery or some other advanced routing rule managed by the admin at the domain level
Would one use Gmail's API, or would that not be appropriate for Action Mailbox?
Even if there were a way to have Gmail fire a webhook on incoming email (I'm not aware of any special delivery options outside the advanced routing rules above), there is currently no way to connect that theoretical webhook to Action Mailbox.
If Gmail doesn't work, what is different about SendGrid that makes it integrate appropriately?
Sendgrid (to use your example, the others work more or less the same way) offers an inbound mail handling API. Just as importantly, the Rails Team has built an incoming email controller to integrate with that API.
Given the lack of Gmail APIs and the lack of a Rails ingress controller, the only way I can think of that you could connect Action Mailbox to an existing Gmail mailbox would be for some other bit of code to check the mailbox, reformat the fetched email and then pose as one of the supported MTAs to deliver it to Action Mailbox.
It would be an interesting exercise and would possibly become a popular gem but it would very much be a kludge. A glorious kludge if done well, but a kludge nonetheless.
Another option would be to leave your example.com domain delivering to Gmail as normal and set up another domain for your Action Mailbox emails. You could use a separate domain, example.org, or a subdomain, app.example.com.
This would involve setting up one of the 7 supported SMTP servers and pointing the MX records for example.org or app.example.com at those servers.
Bonus trivia: Another name for an MTA is a Mail eXchager, hence the name for a DNS mail record is an MX record.
To integrate IMAP with Rails, have a look into the greate mail_room Gem
It's a daemon that you can start alongside your app, which listens onto couple of IMAP inboxes, and then convert those into either a Sidekiq Worker or push it via http to your app.
It's used by Gitlab for their mail interactions (Answer to thread, create issue by writing to an email).
They also have a section on how to integrate with ActionMailbox.
If you were dead set on doing this, Gmail has had IMAP IDLE (push) support since day one.
It would be quite easy to write a small daemon that watches a Gmail inbox and calls the rails action mailbox webhook endpoint with a properly formatted JSON payload.

Using Office 365 Graph API, how to search in sent mails

We need to search mails in Sent Mail folder. Currently it is searching in Inbox alone. What is the call we need to use for searching mail in all folder or the Sent Mail folder?
Graph API gives support to the outlook api. If you are interested in Graph API then try this.
GET /me/mailFolders('SentItems')/messages?$select=sender,subject
You can use well-known folder names such as Inbox, Drafts, SentItems, or DeletedItems to identify certain mail folders that exist by default for all users.
The following should work for you:
GET https://outlook.office.com/api/v2.0/me/MailFolders/{folder_id}/messages
The folder ID, or the Inbox, Drafts, SentItems, or DeletedItems well-known folder name, if you're getting messages from a specific folder. Specifying AllItems would return all messages from the entire mailbox.

Get zoho emails in my rails application

I am trying to fetch emails received and sent from zoho account.
I want to trace all the emails coming to me in outlook or I am sending from outlook.
I have seen zohoCRM, rubyzoho but not able to get things done.
Any suggestions on this.
What you are looking for is a way to build a simple email client with ruby.
There is a simple Ruby Mail library which can get the work done for you. For quick reference, you can check the section "Getting email from a POP server"
Zoho supports POP Access. You should be able to get the access details from there and use it.
The Ruby mail library also support IMAP access and so does Zoho.

Mailcore2: how to receive mail instantly when a new mail arrived?

I'm building an iOS mail client for receiving mails via mailcore2, with IMAP protocol, I've fetched the mail messages successfully. But, how to implement the remote notification push when the target mail account received a new mail in client? I checked the mailcore2 project and some google search results, no luck there.
Please help, thanks!
UPDATE:
Let me clarify the problem details, for the mail client like Airmail in Mac and Microsoft Outlook in iOS, they support to add a IMAP protocol mail account for sending and receiving e-mails, e.g. I added my qq.com mail to Outlook for iOS client, once a new mail arrived to my INBOX in qq mail, I could get an instant remote notification from Outlook client right now.
Let me guess, the mail client didn't upload/save my IMAP-protocol mail config to microsoft/outlook server, all the receiving mail logics just work in local, including communication protocol.
How about IMAP? I've check this article on difference between POP and IMAP. IMAP just keep the client and server have the same account mail data all the time.
Airmail in Mac used mailcore2 in its implementation, so how does it make sure the remote notification work? I don't think they deployed a server side to check the new email arrival for all the user accounts, really.
On mailcore2, I think this is the key point, the remote push should be implemented by it, not some unknown servers. I checked the project structure basically, it's so huge for me and there are many c++ code logics, I must read many mail related blogs before reading it. If someone knows the related guide/wiki/header files, please share to me, or point the mistake on my above guess out, great thanks!

Programmatically read email from inbox on iPhone

Is it possibleĀ for my iOS app to access the user's email inbox in the Mail app? I would like to be able to read the emails and save the attachments.
No. Apple doesn't provide an API for that.
However, you're free to ask the user for their mail server settings and then talk directly to an IMAP server, downloading the attachments yourself.
If you have presets for popular email providers (MobileMe, Gmail, Yahoo, etc.) this won't have to be too difficult for most users to deal with.

Resources