Java Mail ne parvient pas à authentifier les paramètres smtp dans openshift serveur
J'ai écrit la suite de haricot pour authentifier mon mail.
public class Mail_Authenticator {
public Session Get_Auth() {
//sets SMTP server properties
ResourceBundle rs_mail = ResourceBundle.getBundle("mail");
final String userName=rs_mail.getString("username");
final String password=rs_mail.getString("password");
Properties properties = new Properties();
properties.put("mail.smtp.host", "smtp.gmail.com");
properties.put("mail.smtp.port", "587");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.user", userName);
//creates a new session with an authenticator
Authenticator auth = new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, password);
}
};
return (Session.getInstance(properties, auth));
}
}
Le problème est avec les paramètres smtp, quand je lance l'application sur mon serveur local, il fonctionne très bien. Mais quand je lance l'application sur openshift serveur exception est due à
Transport.send(msg);
Pouvait-on s'il vous plaît signaler le problème, dans les paramètres ci-dessus et pourquoi sont-ils travailler dans ma machine locale?
Qui suit est l'exception que je reçois
javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbsWq 534-5.7.14 JJjb_c-FzrtUAccdDqOCMtsPAOL1AwIDSCoireBRoI5X-avznrYbparV84O_zkAvrHXMB9 534-5.7.14 T0Zj8zXP1g1woaWHnTzJQ3vWFn3lwTNl9Kn8Ma9-d9FPD_xB-bMBSh5FEPdaMqID4WljXW 534-5.7.14 v67IfQzXHolKlY48pEiZF-cpGc6CEgknkET1ciEQf51vQuETuMrrzeC7EDcM7s89Njtm5e 534-5.7.14 crMNRLw> Please log in via your web browser and then try again. 534-5.7.14 Learn more at https://support.google.com/mail/bin/answer.py?answer=787 534 5.7.14 54 e7sm180653184qag.7 - gsmtp
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:823)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:756)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:673)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at Servlet.Mail.sendEmail(Mail.java:72)
at Servlet.Mail.doGet(Mail.java:206)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
- vérifier si le port est ouvert sur le serveur, peut-être que c'est fermé?
- Pouvez-vous écrire votre code complet qui comprend msg aussi?
Vous devez vous connecter pour publier un commentaire.
J'ai eu le même problème. Essayez de vous connecter à votre compte gmail à partir d'un navigateur . Gmail bloque l'authentification demande si il pense qu'il s'agit d'un accès illégal(peut-être à partir d'un autre territoire). Vous pouvez voir un message ou une notification. Suivez les instructions de la notification ou de message, puis vous pouvez le débloquer les demandes d'authentification. Votre authentification de travail.
J'avais utilisé le code suivant :
Essayez ceci:
Méthode statique de la classe de Transport est faux parce qu'on n'utilise pas les paramètres de l'objet Session.
Exemple d'utilisation Gmail avec JavaMail
Le code ressemble à ceci: