'Send mail through web application
I am using the following properties to send mail through web application that use jsf but I am getting an error
The properties:
String host = "smtp.gmail.com";
Properties properties = System.getProperties();
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.starttls.enable","true");
properties.put("mail.smtp.socketFactory.port", "25");
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port", "25");
properties.put("mail.smtp.ssl.trust", "*");
Session session = Session.getInstance(properties, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("[email protected]", "password");
}
The error:
javax.mail.MessagingException: Unknown SMTP host: smtp.gmail.com;
nested exception is:
java.net.UnknownHostException: smtp.gmail.com
Solution 1:[1]
Try these on command line.
For SSL:
telnet smtp.gmail.com 465
For TLS/STARTTLS:
telnet smtp.gmail.com 587
If there's no response its a firewall issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ivan Costa |
