Created
August 31, 2021 07:16
-
-
Save kashua14/a5eaafd661b6416c7eba8fc9e088b685 to your computer and use it in GitHub Desktop.
How to login into an email using the Java Mail API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean checkEmailCrendentails(String hostName, String email, String password) { | |
Properties props = new Properties(); | |
props.put("mail.smtp.auth", "true"); | |
props.put("mail.smtp.starttls.enable", "true"); | |
props.put("mail.smtp.host", hostName); | |
props.put("mail.smtp.port", "25"); | |
Session session = Session.getInstance(props, new javax.mail.Authenticator() { | |
protected PasswordAuthentication getPasswordAuthentication() { | |
return new PasswordAuthentication(email, password); | |
} | |
}); | |
try { | |
Store store = session.getStore("pop3s"); | |
store.connect(hostName, email, password); | |
return store.isConnected(); | |
} catch (NoSuchProviderException e) { | |
e.printStackTrace(); | |
return false; | |
} | |
catch (AuthenticationFailedException e) { | |
e.printStackTrace(); | |
return false; | |
} catch (MessagingException e) { | |
e.printStackTrace(); | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment