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("user@gmail.com");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("foo@bar.com");
email.send();
http://commons.apache.org/proper/commons-email/userguide.html
How can I know if the foo@bar.com is real email and it receives the messages ?
email.addTo("foo@bar.com");
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.
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 .
You can check for valid domain of the recipients id by doing something like
boolean result = true;
try {
InternetAddress emailAddr = new InternetAddress(email);
emailAddr.validate();
} catch (AddressException ex) {
result = false;
}
return result;
UPDATE
Or else if you really want to ensure this, then there is some workaround of adding a header field to your html email, I dont remember exactly but something like
email.AddHeaderField("Disposition-Notification-To","<abc@xyz.com>");
could work in this case.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.