This discussion is archived
1 2 Previous Next 24 Replies Latest reply: Feb 20, 2012 8:04 PM by bshannon RSS

How to track Delivery and Read Receipts, to update the e-mail status?

847549 Newbie
Currently Being Moderated
Hi,

I got bit confused, How can I came to know that my e-mail has been successfully sent or not without opening my inbox.

Am sending 50,000 mails per day by using java mail sending program, while sending I am enabled Delivery and Read receipt and I saved message-id in database and I got that receipt back to my inbox.
Then I am reading my Inbox using another java program based on message-id concept, And also I need to parse the body of the mail to update the reason if any message failed.
Here my Inbox received more than 1 lac mails per day as receipts. Because am sending 50,000 mails, So, I got 2 receipt mails for 1 mail, totally 50,000*2=1lac mails in Inbox. My problem is, my reading Inbox java program not able read all 1lac mails at one day. It just reading 5,000 mails per day. When my next day mail sending process started, again i am getting another 1 lac receipts.
Since I am not able to read and delete the receipts completely, mail counts in my inbox getting accumulated. So, I got stuck, How can I do this?
If anybody have any other ideas please share with me.

Already I surfed on net lot, but I can`t find solution for this concept.

Thanks in advance.
  • 1. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    bshannon Pro
    Currently Being Moderated
    Did you read this FAQ entry?
    http://www.oracle.com/technetwork/java/javamail/faq/index.html#bounce

    If you can't process the receipts fast enough, you need to do some performance
    analysis on your program.
  • 2. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    EJP Guru
    Currently Being Moderated
    Agreed. You should be able to read 5000 emails in a few minutes, not a day.
  • 3. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    847549 Newbie
    Currently Being Moderated
    Hi bshanon,
    Thanks for your prompt reply..
    Am asking how to do this things efficiently...I already tried this concept using threading and am doing string parsing using regex..but nothing improved my preforamance..
    I don`t think so, whether my way of reading mails are correct or not.?
    Assume, you have those 1 lac receipts in your Inbox and you have to read and update the status. What will you do in this situation? am awaiting for your ideas..
    Hope you have some fresh ideas.

    Once again thanks for your reply..

    Edited by: 844546 on Mar 15, 2011 11:34 PM
  • 4. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    bshannon Pro
    Currently Being Moderated
    Use a performance analysis tool. Find out which part of your application is taking all the time.
  • 5. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    EJP Guru
    Currently Being Moderated
    whether my way of reading mails are correct or not.?
    Clearly not, as you are getting the wrong performance by two or three orders of magnitude. Impossible to comment further without seeing some code.
  • 6. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    847549 Newbie
    Currently Being Moderated
    As suggested I have downloaded one performance analysing tool called PerfAnal.jar. I will do my testing.

    If you have any other idea(out of box idea) to keep track the delivery and read receipt of sent mail, please share that idea with me. It really helpful to me.
    If your idea better than mine then I can go for it.
    Thanks a lot for your advise..I don`t think so, whether reading that entire receipts will be a good idea or not?

    Edited by: 844546 on Mar 15, 2011 11:59 PM
  • 7. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    847549 Newbie
    Currently Being Moderated
    Hi EJP/Bshanon,
    As you asked, am not able to put all the code here, it was very lengthy code.
    For your understanding, here am posting the flow of code steps below.

    step 1: connecting exchange server and open inbox folder
    step 2: Taking total inbox length using message.length; Ex: n = message.length;(n = 50000)n is the mail count of inbox
    step 3: In for loop, for(i=0; i < = n; i+){+  //--here we are getting mails one by one
    step 4: getting whole plain/text body of mail number i.
    step 5: In that mail body we are searching our own unique keyword(which we set for our unique mail reference)
    step 6: If we found that keyword then we are consider that mail as our`s mail.
    step 7: If keyword found then we are updating our database using unique keyword.If not found then we are skip the process and delete that mail.
    step 8: After reading that 1st mail, we are deleting that mail.
    step 9: This same process will continue, until step3`s for loop will not true.

    Above are steps which am using now to update the status of sent mails in database.
    If you have any other idea to improve this, it will be highly appriciated.
    Thanks in Advance.
    If you want I will post my code in next post as short one.
    Awaiting for your reply.

    Edited by: 844546 on Mar 16, 2011 5:57 AM
  • 8. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    bshannon Pro
    Currently Being Moderated
    If you haven't figured out how to use a real performance analysis tool,
    just use System.currentTimeMillis() around each one of those steps to
    see which step is taking the most time.
  • 9. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    EJP Guru
    Currently Being Moderated
    step 2: Taking total inbox length using message.length
    The message count is available via Folder.getMessageCount().
    step 3: In for loop, for(i=0; i < = n; i+){+ //--here we are getting mails one by one
    That should be i < n, not i <= n.
    step 5: In that mail body we are searching our own unique keyword(which we set for our unique mail reference)
    Searching how?
    If you want I will post my code in next post as short one.
    I have already asked for that.
  • 10. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    847549 Newbie
    Currently Being Moderated
    Hi EJP,

    step 2: Taking total inbox length using message.length
    The message count is available via Folder.getMessageCount*().//ok I will try this one.*

    step 3: In for loop, for(i=0; i < = n; i+){+ //--here we are getting mails one by one
    That should be i < n, not i <= n. *//here I was wrongly specified, I used i<n only.*

    step 5: In that mail body we are searching our own unique keyword(which we set for our unique mail reference)
    Searching how?

    In order to find the keyword, we are getting entire text/plain mail body using below method,
    //To get body plain/text body part start here
         public static void getTextPlainBodyPart(Part p) throws Exception {
              if (p.isMimeType("text/plain")) {
                   if (!(showStructure) && !(saveAttachments)){
                       lstr = (String)p.getContent();
                  }
              }else if (p.isMimeType("multipart/*")) {
    
                 Multipart mp = (Multipart)p.getContent();
                 level++;
                  int count = mp.getCount();
                  for (int i = 0; i < count; i++){
                 getTextPlainBodyPart(mp.getBodyPart(i));
                  }
                  level--;
              }
    
             }
    //To get body plain/text body part end here
    Above method will return entire body of the mail in one string variable, Eg: String mailBody;(*mailBody variable contains entire body)*

    Then using mailBody variable we are searching our own keyword(which we set for our unique mail reference while sending mail) using below technique,
    if(lstr.indexOf("!$*#*$") != -1 && lstr.lastIndexOf("$*#*$!") != -1){
    KeyWord = lstr.substring(lstr.indexOf("!$*#*$")+3,lstr.lastIndexOf("$*#*$!"));
    
    //to get reason alone
    if(lstr.contains("Reason:")){
         Pattern p = Pattern.compile("Reason:\\s([^\\n])*");
    Matcher m = p.matcher(lstr);
    boolean result = m.find();
         while(result) {
    
            reason = m.group();
             result = m.find();
         }
    //System.out.println("Reason:>>>>"+reason);
    }else{
         reason = "";
         
    }
    }
    After getting that keyword in KeyWord variable,
    then we are updating our database using that KeyWord,(here we are using KeyWord variable in where condition in update query)
    Note:_ KeyWord is nothing but, we were stored all our unique keyword against every mails while sending.So, If when get that keyword while reading the receipts,then we can update our table using that same keyword.

    guide how can I do this effieciently. And if you any other new concept please share with me.

    Thanks in advance..

    Edited by: EJP on 17/03/2011 16:54: added code tags. Please use them. Code is 100% illegible otherwise.
  • 11. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    EJP Guru
    Currently Being Moderated
    if(lstr.indexOf("!$*#*$") != -1 && lstr.lastIndexOf("$*#*$!") != -1){
    KeyWord = lstr.substring(lstr.indexOf("!$*#*$")+3,lstr.lastIndexOf("$*#*$!"));
    So here you are searching the same string for the same two things twice instead of once each. You can easily find a way to double its speed. Think about it.
         Pattern p = Pattern.compile("Reason:\\s([^\\n])*");
    You are wasting time here by recompiling this regex every message. Make the variable an instance variable and initialize it there.
  • 12. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    847549 Newbie
    Currently Being Moderated
    Hi EJP,

    if(lstr.indexOf("!$#*$") != -1 && lstr.lastIndexOf("$*#*$!") != -1){*

    By using above condition only we are come to know, whether that reading mail is belongs to ours(delivery/read receipts mail) or not ours.
    Then only we are getting that keyword using below line

    *KeyWord = lstr.substring(lstr.indexOf("!$*#*$")+3,lstr.lastIndexOf("$*#*$!"));*

    Am really stuck here please tell me..how I double the speed.

    Thanks again..
  • 13. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    bshannon Pro
    Currently Being Moderated
    Having done no performance analysis at all, you have no idea whether this is worth it.
    You might be doubling the speed of code that is only 1% of your app. You would be
    wasting your time and see no improve,

    Ya, you could take the shotgun approach, and tweak every line of code trying to make
    it faster. But wouldn't it be better to have some actual data? For some reason you
    just don't seem to want to do that...
  • 14. Re: How to track Delivery and Read Receipts, to update the e-mail status?
    EJP Guru
    Currently Being Moderated
    Am really stuck here please tell me..how I double the speed.
    By calling those methods once each instead of twice each, which will require an amazing concept called a variable to hold the results of the call in.

    Surely this is obvious?
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points