I would like to know if it is possible to know if a recipient has answered a definit email .
What is te best way to do this in Java ?
There are Message-ID, In-Reply-To and References headers in the e-mail message (see http://cr.yp.to/immhf/thread.html or http://wesmorgan.blogspot.ch/2012/07/understanding-email-headers-part-ii.html). You have to keep the Message-ID of an e-mail message you are interested in, and then parse the headers of the incoming messages, if they contain your ID.
As for the way to do it in Java, read the Java Mail API Tutorial and study the javax.mail JavaDoc (and sub-packages).
Warning: Athough commonly used by most e-mail clients, these headers are not mandatory, so there is no 100% secure way to do it.
Just to be sure we understand the problem, you want to know how to tell if a recipient has sent a reply to you for a message you sent to the recipient, right?
As Jozef describes, the In-Reply-To and References headers are the standard way of doing this, but some mailers don't properly include them in replies. Another approach is to include a unique ID in the Subject of the original message. Replies almost always include the original Subject without change, prepended by "Re:" or equivalent.
Related
I have a java application that monitors an inbox and reads new messages. I only want the latest message in a thread read, however when an email with multiple replies in the same thread is parsed, it reads the whole thing.
Is it possible to read only the latest reply in an email thread using javax.mail? Or would I need to place some logic to look at the header and determine the latest by comparing the send date?
If you have separate messages in your mailbox for each reply, you have to decide how to determine that they're part of the same "thread". There's no perfect way to do this and different mailers will do it differently. A good start is the References and In-Reply-To headers. Once you know the set of messages that are part of a single thread, you can choose the latest one by date.
If you have a single message that includes the text of previous replies in the body of the message and you want to separate the latest reply from the previous replies, you'll have to process the text in the body and decide which parts are previous replies and which part is the current reply. Again, there is no perfect solution and this will require more heuristics.
When using Javamail API to iterate through messages, uncertain how to deal with multiple body parts. When I reply to it I would like for the reply to look be formatted as the incoming message.
First, you need to separate the main body of the message from the attachments. See the JavaMail FAQ to get started. This will give you the plain text and/or html text of the message.
Next, you need to decide how you're going to edit the original message to include the text from the reply. JavaMail doesn't help you with this. Are you going to display the message to a user or are you going to edit the text programmatically? Either way, this is likely to be the most difficult part unless you only deal with plain text messages.
Finally, with the new text, you can use the JavaMail Message.reply method to create the reply message and then set the content of the message using the edited text for the reply. Note that it's more complicated if you want to support multipart/alternative messages with both a plain text and html part, and even more complicated if the html part is part of a multipart/related that includes images that it refers to. An appropriate search will turn up many examples.
That's just a brief sketch of what's involved. If you have more specific questions, show us your code.
Now I would like to check if an incoming email is duplicate via IMAP using javamail,
which may mean one email equals others that they have the same Subject,From,To,CC,BCC,Body,Attachements.But I donnot find any APIs to support this.
So can anybody tell me how to do this. any ideas are much appreciated.Thanks
If you mean literally duplicated emails, checking for two messages with the same Message-ID is probably the simplest. If you just mean two emails that are "similar", you'll need to compare all the individual pieces yourself. There are APIs to access all the parts of the email, but you'll have to write the comparison logic yourself.
Services like : http://www.wbwip.com/wbw/emailencoder.html encodes email to ASCII. Is it totally safe? Can spammers copy this code and decode it?
They can decode it, so how is it safest to show your email on the website? Probably by putting it in the image?
No, it is not safe at all. You are still exposing your email address on the page. Some dumb spiders will end confused, but those which are up to date will definitely be able to "decode" these entities quickly. The only solution is to... not expose email address at all. If you use contact form with recipients to be chosen by users, use IDs and dereference it in your code. If you need to show email - show image, but if anyone would like to have you address in their spam DB, then he can always put it by hand there.
Short answer - no, it is not fully secure as it can easily be decoded by anyone.
Anyone could easily decode this using an ASCII table, like so: http://www.asciitable.com/
A clever spam bot can trivially read the "hidden" address.
What you should do instead, is have something like (for john.doe#gmail.com):
john (dot) doe (at) gmail (dot) com
One could still construct a bot to counter this, but it would be impractical as this technique isn't very common.
Truth be told, there's no 100% way of hidhing your email. Even images have OCRs, and in the worst case, a persistent human can always manually type your address and add it to his to-spam list.
If you want your users to contact you, the best way would be to make a form, and have the server to process the request and send you an email. This way, your address is not exposed to anyone.
The best solution is not to show the email address at all. If you want your users to be able to send emails to each other, write a dedicated UI where they can type the message in and send the email directly from your server. But make sure that the UI itself is secured with login/pass too, otherwise you're back to square one.
That method would be safe against some - but not all spiders. If even one got through, you could be introducing the user to thousands of emails of spam. I guess it's up to you whether it's worth the risk, but I definitely wouldn't.
Sure, this form of email encoding is very weak in terms of security, in fact, it is not design for security purposes at all. It's encoding, not encrypting.
We have a module which will send reminder mail. We are using apache commons email library for sending mail. We have no issue if we send mail only one email address using addTo method of HtmlEmail, but we are encountering exception when we are trying to send the same mail to more than a user using setTo which accepts Collection.
Even commons mail javadoc mentioned that this method is to send mail to a group of email address but surprisingly its not working.
Is there any workaround to solve this problem or hint to proceed with right direction?
Did you make sure, that your Collection contains only objects of the expected Type? Exerpt from the JavaDoc for setTo(java.util.Collection):
Set a list of "TO" addresses. All elements in the specified Collection
are expected to be of type java.mail.internet.InternetAddress.
Providing source code or exceptions for your problem would make it easier to help you to find the solution to your problem.