Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know if my sent email reach the receiver or not java?

I am using this code to send email

Email email = new SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setSSLOnConnect(true);
email.setFrom("[email protected]");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("[email protected]");
email.send();

http://commons.apache.org/proper/commons-email/userguide.html

How can I know if the [email protected] is real email and it receives the messages ?

 email.addTo("[email protected]");
like image 431
Mohammed Subhi Sheikh Quroush Avatar asked Oct 03 '22 21:10

Mohammed Subhi Sheikh Quroush


2 Answers

There is no reliable way to track email delivery without proprietary APIs and infrastructure. Based only on SMTP, POP and/or IMAP, there is no way to make completely sure, that the email was read.

There are options, however, that might give you some degree of information about the validity of the address (starting with an email address parser), listening to error messages that might get sent from the receiving server (Bounce message) and requesting delivery notifications (Return receipts).

Additionally you could send an HTML email and embed a link to an image and track if the URL has been called. But even this is not reliable, because email clients might not display images, the URL might have been called by a virus scanner etc. That means you might get a lot of false positives / negatives.

like image 51
Moritz Petersen Avatar answered Oct 07 '22 17:10

Moritz Petersen


You need to use the POP3 capabilities of JavaMail.

You have a sample here: http://alvinalexander.com/java/javamail-pop-pop3-reader-email-inbox-example

I if remember well: server is pop.gmail.com and port is 995.

like image 43
Pragmateek Avatar answered Oct 07 '22 16:10

Pragmateek