Javamail pull messages in chunks (like pagination) GMAIL POP3 - pagination

Through Java app I am able to connect with GMAIL POP3 server. When I call getMessageCount() it returns me 280, though I have more than 10k mails in my Inbox. So, when I call folder.getMessages(300, 400) it gives me error because range is more than 280. For more details see my another post link
My question is:
Is their any API to get pull emails in chunks (like as pagination)? if so can anyone give me reference to start with it.

This is not a javamail limitation, this is a gmail limitation of their POP3 server. When accessing over POP, it will only show you 300ish messages at a time until you remove them. There is an alternate access method where you specify the login as recent:user#gmail.com, where instead it will show you the last 30 days worth of email.
They do this because POP3 rapidly becomes a very inefficient protocol for accessing thousands of emails, so they limit the window of messages you can see.
If you wish to access all the email, you will need to either switch to IMAP, or use the Gmail REST API, both of which have vastly improved mail access and experiences.

Related

Seeing a lot of SendGrid Activity marked "Deferred" after disabling a mailbox

Using SendGrid through Azure (free version).
I recently disabled a user's email because it was receiving way too much SPAM. Prior to doing this my activities list was about 1-2 pages long with recognizable e-mails my system was sending out per customer input in a website (there is a workflow for forms which the user inputs, then my system sends out an e-mail confirming input).
Now that I have disabled that e-mail, I am seeing upwards of 59 pages of activity just for one day (since I disabled the e-mail address), most of which is listed as "Deferred" or "Processed". The lists include SPAM e-mail addresses (something-reverse-mortgage#whatever.net, etc.).
Reading the SendGrid documentation, it seems that "Deferred" activities just mean that the receiving ISP is asking SendGrid to slow down. I take this to mean that my server is sending these e-mails.
This is worrisome obviously. Disabling that e-mail has this unintended consequence of seeing hundreds of "Defered" activity listings in SendGrid.
I am confused, however, if this is just the system getting these e-mails and then trying to bounce them back through my server. Since it's SPAM and likely not a real e-mail address, is SendGrid just trying to return the e-mails? Hence the activity?
If so, is this something that will eventually die down, or should I do something to prevent SendGrid from returning these obviously bogus SPAM e-mails to what it thinks is the originating sender?
Thanks in advance.
I send about 100K emails a month with sendgrid and I don't worry at all about deferred. About 1/3 of my outgoing emails are gmail and gmail is very agressive at blocking emails when you send more than 50 or so at once. They simply reject and sendgrid tries again later. They all seem to go thru within about 24 hours.

trigger a .sh script when a specific subject email is received

Anyway, I have a script that I want to run whenever I receive an email on gmail. And if possible a subject specific email. is such a thing possible and if so, what programs do I need to allow it.
You can't instruct gmail to trigger an external script for you. I think you've got a few basic choices. In order of increasing difficulty and complexity:
1) Configure a gmail filter to deliver your desired messages to a special folder. Write a script to poll that folder, download (or delete or mark as read) messages it finds there, and then launch your local script. Set up a cron on your local machine to run the script every few minutes. You can poll the folder with IMAP or the GMAIL API. IMAP is probably easier. This will be tricky with shell, you're better of with Python, PHP, or similar.
2) Configure a gmail filter to forward your desired messages to an address on a mail server that you control. Use procmail or similar to intercept the incoming messages and launch your script.
3) Set up an account at Mailgun and configure the emails so they get delivered there directly. (Or forward from gmail as in #2.) Configure Mailgun to launch an API request when it receives messages. Build an API handler to receive the request. Launch your process from your API handler.
I have never done it, but I guess the first thing you should do is to take a look at the Google's Gmail API...
What is the Gmail API?
The Gmail API gives you flexible, RESTful access to the user's inbox,
with a natural interface to Threads, Messages, Labels, Drafts, and
History.
It seems to fit what you want - at least, without knowing the details of what you want to do.
The Gmail API can be used in a variety of different applications,
including, typically:
Read-only mail extraction, indexing, and backup
Label management
(add/remove labels)
Automated or programmatic message sending
You can use several programming languages - maybe the trick is using your programming language of choice to write a wrapper for the .sh script... I hope this helps!

Maximum sending rate and daily quota for Gmail+Google Apps Script?

I wrote a small Google Apps Script to send out personalized e-mails (conference invitations) individually to recipients (i.e. one recipient per e-mail). As a workaround to the issue of e-mails sent using GmailApp.sendEmail not showing up in the Sent Mail folder, I have one script send the e-mails to itself (i.e. the sender and recipient are the same), then another script to forward those to the appropriate recipients. There are only about 100 (maybe less) verified recipients, but I'm concerned that sending out the e-mails as fast as the script executes might get them flagged as spam due to the rate at which they are being sent. My questions are the following:
If a Google Apps Script accesses a Gmail account to send and forward e-mails using GmailApp, does it incur a sending rate limit (e.g. in e-mails/second, kB/second, etc.)?
Which quota applies to said script? Is it Gmail's 500/day or Google Apps' 100/day?
P.S. I found this discussion about quotas, but I'm not sure if my case falls under either of the scenarios described therein.
There are no such limits. There is a limit on the body size per email - 20KB
It's 500 emails/day for Gmail users and free Google Apps users. Please note though that CCing and BCCing are all counted against your quota. So if you send one email and CC it to 500 hundred people you would have used up all your quota for that day. Also, there are additional quotas when sending emails within a domain.
Also, the method MailApp.getRemainingDailyQuota() will tell you how many more emails you can send that day.
All the quotas are described here:
https://developers.google.com/apps-script/guides/services/quotas
How are e-mails sent using GmailApp.sendEmail not showing up in the Sent Mail folder?

How to prevent emails from a specific address going to Hotmail SPAM?

I have a site on a dedicated server with it's own IP range that has been running for a good few years. We have a notification email address (mailout#domain.com) which we use to send automated emails (activation emails when a user signs up and notification emails if something relevant to them happens, eg someone befriends them or comments on their picture etc). Users can select whether to receive these notifications or not. We have SPF and RDNS setup.
Email from all our other email accounts go to hotmail/gmail/yahoo mail etc correctly into the inbox. However any mail sent from the mailout#domain.com account (whether automatically by the server or manually via outlook) is delivered correctly to the inboxes for yahoo and gmail however goes into Junk in Hotmail (but other #domain.com addresses deliver to hotmail's inbox correctly). It says at the top of the message that MS Smartscreen marked this message as junk. I signed up for MS Smart Network Data Services to monitor the IP and it says it's not blocked but it displays Bot-like behaviour (which kind of makes sense as our notifications are kind of bot like even though they're not spam).
I can't work out what to do to prevent this from happening, we've authenticated the email, there's obviously not a general block on the IP as emails from different accounts on the same domain are going through successfully. It doesn't seem to be the format of the email either because if I send identical emails from mailout#domain.com and contact#domain then the one from contact# gets through to the inbox but the one from mailout# goes through to junk.
I can't really work out what to do and obviously trying to get MS to sort it out is never going to happen and i've used all their available tools. I can obviously try setting up a new email address (eg noreply#domain.com) and using that for notifications but i assume it will only be a matter of time before that gets blocked as well.
I would be immensely grateful for any suggestions anyone has!
Thanks so much,
Dave
You don't have many options. Try to do as many of the following as you can:
Reach out to MS support (don't discard this notion)
Implement DKIM and possibly DMARC (which are vastly more informative than SPF)
Change your IP address to something cleaner
Find and follow bulk sender best practices, e.g. M³AAWG's BCPs, perhaps the Help – I'm on a Blocklist doc

Link to individual mails in gmail

I want to download all emails in a gmail account and also want to get the unique url which will open the exact mail in gmail, off course with authentication. I tried using javax.mail imap library but Imap probably doesn't supports anything like it.
I can use "https://mail.google.com/mail/feed/atom" gmail feeds. but won't give me entire email and it only gives unread email and I don't want to miss any email
You can do this if you are using Google Apps for Business/Education. If you are, you can access the Gmail inbox feed (Atom) by using OAuth. OAuth can also be used to access Gmail via IMAP - you can then have complete access to the IMAP server programmatically, see Gmail IMAP and SMTP using OAuth.
Google has extended IMAP to allow developers to provide a more Gmail-like experience via IMAP, see: (Gmail IMAP Extensions, X-GM-EXT-1).
The unique message (X-GM-MSGID) and unique thread (X-GM-THRID) ids can be used to produce links to Gmail messages directly - you just have to hex encode the id long (e.g. Long.toHexString(x_gm_msgId)). Your link will then need need to be in the form of:
http://mail.google.com/mail?account_id=ACCOUNT_ID_HERE&message_id=MESSAGE_ID_HERE&view=conv&extsrc=atom
supplying ACCOUNT_ID_HERE (something like user#someplace.com) and MESSAGE_ID_HERE as appropriate.
I have been working in this area and think you might find my project useful, see: java-gmail-imap.
[NB: URLs formatted as above do not work on Gmail's mobile site (at least on iPhone/Safari).]
https://mail.google.com/mail/#all/HexEncodeMessageID
replace the HexEncodeMessageID part with the ID. You get it, when you open the email in a new window (use the pop out icon in the upper right corner.
The id looks like this: search=inbox&th=1426b8f59e003aa0
I'm fairly confident this is not possible - that there is no reliable way to get the unique URL that'll lead to a single email in Gmail. I'd love to hear otherwise!
I do believe it is possible to get a URL that will lead to the Gmail thread containing the message - but you have no control over which message(s) are "expanded" in this threaded display.

Resources