How to handle Delivery Status Notification of GMail - java

Does gmail support RFC1892(Delivery Status Notification) ?
If so, how can I use JavaMail to parse the DSN. (Sample code is highly appreciated)
If not, When a email can't be delivered through gmail, a failure message is returned. How can I detect these "bounced" messages?

1 - I don't know.
2 - Add dsn.jar from JavaMail to your classpath. Then use something like this:
if (msg.isMimeType("multipart/report")) {
MultipartReport r = (MultipartReport)msg.getContent();
// see com.sun.mail.dsn package javadocs for MutlipartReport
}
3 - http://www.oracle.com/technetwork/java/javamail/faq/index.html#bounce

Related to this question.
The X-Failed-Recipients header seems to be the quickest way to identify gmail DSN. After that, it seems you must parse the text/plain content.
The subject seems to be Delivery Status Notification (*status*) where statuses that I've seen are: Failure, Delay.

Related

Gmail watch user inbox, history.getMessagesAdded is not returning the new message

Requirement is to sync mails from Gmail for an user into our CRM. The system in place is based on Google Pub/Sub which watches inbox of the user for any change and fires the notification to our HTTPs endpoint. More on this at Gmail cloud pub/sub.
Based on the above procedure we git history of changes. And then i am interested in only new messages, so history.getMessagesAdded is preferred as per this guide. Issue we are facing now is the first mail of a thread is not captured under messagesAdded all the subsequent messages are passing through our system.
Note: For the first mail, we do get push from Google. But when we try to get Messages added it turns out empty. Is there anything special needs to be done for the first mail of the thread or am i missing out something.
I was experiencing a very similar problem, and my mistake was that I was using the historyId from the push notification, the solution was to store the last known historyId on my database, so, every time I get a notification, I get the history from the id I have stored, not the one from the notification.
In my case, the historyId from the notification doesn't even make part of the history, maybe because of my watch restrictions: labelIds=['INBOX']
This is the google pub/sub notification:
{
message:
{
data: {"emailAddress": "user#example.com", "historyId": "9876543210"},
message_id: "1234567890",
}
subscription: "projects/myproject/subscriptions/mysubscription"
}
I was using the message.data.historyId, wich was causing the confusion!
The message.data, comes as a base64 encoded string, in this example I just decoded it!
Step by step for watching new e-mails on the inbox:
Do all the configuration in the google pub/sub.
Start watching the user with the filters you want (docs.: https://developers.google.com/gmail/api/v1/reference/users/watch)
Store the historyId obtained in the step 2
When receive the notification, get all the events (history) using the stored id as the startHistoryId parameter (docs: https://developers.google.com/gmail/api/v1/reference/users/history/list)
In the history list obtained on the step 4, look for the new messages: history.getMessagesAdded().
Update the last known history id in your database, so you don't need to deal with the whole history every time!
I hope it helps.

Spring IAMP Mail receiver not reading all emails everytime [duplicate]

I have a piece of code which uses spring integration's IMAP adapter to poll an inbox to read all incoming emails which are unread and that works perfectly. But if I open any email message and and then mark it as "unread" in my outlook inbox the poller doesn't fetch the marked email.
I can use the pop3 adapter which fetches all the email, but deletes them afterwords, but I want to keep the emails in my inbox and I want the poller to fetch all the email which are unseen.
Any suggestions to handle this problem? I been searching and reading articles on email adapters but didn't find anything useful.
Thanks in advance.
Looks like you need custom 'search-term-strategy'. From Spring Integration (SI) documentation:
By default, the ImapMailReceiver will search for Messages based on the default SearchTerm which is All mails that are RECENT (if supported), that are NOT ANSWERED, that are NOT DELETED, that are NOT SEEN and have not been processed by this mail receiver (enabled by the use of the custom USER flag or simply NOT FLAGGED if not supported). Since version 2.2, the SearchTerm used by the ImapMailReceiver is fully configurable via the SearchTermStrategy which you can inject via the search-term-strategy attribute. SearchTermStrategy is a simple strategy interface with a single method that allows you to create an instance of the SearchTerm that will be used by the ImapMailReceiver.
And here is a post from SI forum with funtastic Oleg's explanation: Server does not support RECENT or USER flags
And here you can find SI DefaultSearchTermStrategy: it's a place to determine how you should implement your own strategy. I guess, you case is:
This email server does not support RECENT flag, but it does support USER flags which will be used to prevent duplicates during email fetch.
Switch SI-mail logging level to DEBUG and take a look, which flag supports your email server.

ical4j Api, create new notification with OOF status

I am creating a new event calendar using ical4j plugin. I am using outlook to receive this notification.
This one must be show like an "absense" ( Out Of Office).
For this, i use property X-MICROSOFT-CDO-BUSYSTATUS = OOF.
When i receive this notification, in outlook, it looks like "busy" and not like "out of office".
Heres it content of .ics file
BEGIN:VCALENDAR
PRODID:-//Microsoft Corporation//Outlook 14.0 MIMEDIR//EN
VERSION:2.0
METHOD:REQUEST
BEGIN:VEVENT
DTSTAMP:20140324T121412Z
DTSTART:20140804T000000
DTEND:20140805T000000
SUMMARY:absense
ATTENDEE;CN=Resp 1;RSVP=FALSE:mailto:toto.toto#test.com
SEQUENCE:0
CLASS:PUBLIC
STATUS:TENTATIVE
ORGANIZER;CN=res:mailto:etoto.toto#test.com
PRIORITY:5
TRANSP:OPAQUE
UID:123456789123456789aabbcc
X-MICROSOFT-CDO-BUSYSTATUS:OOF
X-MICROSOFT-CDO-IMPORTANCE:1
X-MS-OLK-CONFTYPE:0
X-MICROSOFT-DISALLOW-COUNTER:FALSE
X-MS-OLK-AUTOFILLLOCATION:TRUE
CREATED:20140324T121412Z
END:VEVENT
END:VCALENDAR
how can i do, to have the correct status of this notification in outlook ? is there something incorrect in my file ?
thank you
You mention receiving this REQUEST. If we translate this in iTIP workflow, we have etoto.toto#test.com (ORGANIZER) inviting toto.toto#test.com (ATTENDEE) to an event. So on the Outlook side (attendee side), you are receiving an invitation.
It would be weird if any arbitrary organizer could set your freebusy status to Out of Office, don't you think.
In other words, I think it make sense for Outlook to ignore the X-MICROSOFT-CDO-BUSYSTATUS.
On the other hand, if you remove the METHOD, ORGANIZER and ATTENDEE properties, and if you import the event, you may see the OOF value being taken into account (have not tried it myself).

Twiiter4J getDirectMessages() does not work anymore?

I am using Twitter4J 2.2.5 (latest, tried other versions). And can no longer get direct messages to work at all. The same code used to work a while ago. I assume Twitter changed something.
I'm using
Twitter.getDirectMessages()
and it gives the error below. No idea why, I can see the direct messages for the account if I login, but always get this error. The limit error makes no sense, as the account is no where near the limit.
Other API work, like followers/fried/status/etc.
403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (http://support.twitter.com/forums/10711/entries/15364).
Relevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=00919618 or
http://www.google.co.jp/search?q=332bf6ca
TwitterException{exceptionCode=[00919618-332bf6ca], statusCode=403, retryAfter=0, rateLimitStatus=RateLimitStatusJSONImpl{remainingHits=107, hourlyLimit=350, resetTimeInSeconds=1328297, secondsUntilReset=1116, resetTime=Fri Feb 03 14:39:45 EST 2012}, version=2.2.2}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:189)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:93)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1721)
at twitter4j.TwitterImpl.getDirectMessages(TwitterImpl.java:874)
at org.pandora.sense.twitter.TwitterDirectMessaging.checkDirectMessages(TwitterDirectMessaging.java:44)
at org.pandora.sense.twitter.TwitterDirectMessaging.checkProfile(TwitterDirectMessaging.java:35)
at org.pandora.sense.twitter.Twitter$1.run(Twitter.java:100)
at java.lang.Thread.run(Thread.java:662)
Twitter has some time ago changed the rules for direct messages. An app must be especially authorized by the user to access the direct messages.
Did you make sure this is true for you? You may go to the twitter web site and check for the app.
To get the direct message you should try the below code.It works for me.
getDirectMessages(); gives list of direct messages. We need to put for loop to get text of each message.
List<DirectMessage> messages = twitter.getDirectMessages();
for (DirectMessage message : messages)
{
System.out.println(message.getText());
}
Let me know if you get any error.

Log4J SMTP digest/aggregate emails?

I have a JBOSS batch application that sometimes sends hundreds on emails in a minute to the same email address with Log4J errors. This causes problems with Gmail, because it says we are sending emails too quickly for that gmail account.
So I was wondering if there was a way to basically create a "digest" or "aggregate" email puts all the error logs in 1 email and sends that every 5 minutes. So that way every 5 minutes we may get a large email, but at least we actually get the email instead of it being delayed for hours and hours by gmail servers rejecting it.
I read this post that suggested something about using an evaluator to do that, but I couldn't see how that is configured in the Log4J xml configuration file. It also seemed like it might not be able to "digest" all the logs into 1 email anyway.
Has anyone done this before? Or know if it's possible?
From (the archived) SMTPAppender Usage page:
set this property
log4j.appender.myMail.evaluatorClass = com.mydomain.example.MyEvaluator
Now you have to create the evaluator class and implement the org.apache.log4j.spi.TriggeringEventEvaluator interface and place this class in a path where log4j can access it.
//Example TriggeringEventEvaluator impl
package com.mydomain.example;
import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.spi.TriggeringEventEvaluator;
public class MyEvaluator implements TriggeringEventEvaluator {
public boolean isTriggeringEvent(LoggingEvent event) {
return true;
}
}
You have to write the evaluator logic within this method.
I created a free useable solution for log4j2 with an ExtendedSmtpAppender.
(If you still use log4j 1.x, simply replace your log4j-1.x.jar with log4j-1.2-api-2.x.jar - and log4j-core-2.x.jar + log4j-api-2.x.jar of course.)
You get it from Maven Central as de.it-tw:log4j2-extras (This requires Java 7+ and log4j 2.8+).
If you are restricted to Java 6 (and thus log4j 2.3) then use de.it-tw:log4j2-Java6-extras
Additionally, see the GitLab project: https://gitlab.com/thiesw/log4j2-extras (or https://gitlab.com/thiesw/log4j2-Java6-extras)
[OLD text:
If you use log4j2, see answer to other stack overflow issue: https://stackoverflow.com/a/34072704/5074004
Or directly go to my external but publically available solution presented in https://issues.apache.org/jira/browse/LOG4J2-1192
]

Categories

Resources