I want to validate an email address in Java before sending an email.
That email address may exist on the server or not.
How can I test it?
I don't have any idea.
Is there a way to check that a given email address exists on the server side?
I want to validate an email address in Java before sending an email.
That email address may exist on the server or not.
How can I test it?
I don't have any idea.
Is there a way to check that a given email address exists on the server side?
If you are store your email addresses in database, you need to create method that fetch the email address from the database, and your method is completely depends on the technologies and DBMS that you are working on.
public boolean isEmailExist(String email) {
String selectSQL = "SELECT USER_EMAIL FROM USER WHERE USER_EMAIL = ?";
PreparedStatement preparedStatement = dbConnection.prepareStatement(selectSQL);
preparedStatement.setString(1, email);
ResultSet rs = preparedStatement.executeQuery(selectSQL);
return rs.next();
}
I hope this helpful, enjoy!
You can't.
This is one example of a very general kind of problem: trying to predict the future. The most effective way to test whether any resource is valid and available is to try to use it in the normal way. Anything else is basically fortune-telling. It might be valid at the moment you test it and invalid when you try to use it, or vice versa.
This applies to files, email addresses, servers, ...
It seems there is no straight forward way to check if the email address is available on the mail server or not in Java. There is a workaround for it, see this post: