Buenas quiero enviar mensajes de email pero me da un error y no se porque, la contraseña esta bien puesta
El codigo es el siguiente:
public void enviarCorreos(){
final String correoEnvio = "[email protected]";
final String contraseña= ""; //en la aplicación esta puesta
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Properties properties = new Properties();
properties.put("mail.smtp.host", "smtp.googlemail.com");
properties.put("mail.smtp.socketFactory.port", "465");
properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.port", "465");
properties.put("mail.imap.ssl.enable", "true"); // required for Gmail
try {
Session session = Session.getDefaultInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(correoEnvio, contraseña);
}
});
if (session!= null){
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(correoEnvio));
message.setSubject("holaaa");
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("[email protected]"));
message.setContent("holaaa","text/html; charset=utf-8");
Transport.send(message);
}
} catch (Exception e){
e.printStackTrace();
}
}
Y me da el siguiente error
05-28 16:42:06.875 1992-1992/com.example.sergio.playbetwincliente W/System.err: javax.mail.AuthenticationFailedException
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at javax.mail.Service.connect(Service.java:319)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at javax.mail.Service.connect(Service.java:169)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at javax.mail.Service.connect(Service.java:118)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at javax.mail.Transport.send0(Transport.java:188)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at javax.mail.Transport.send(Transport.java:118)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at com.example.sergio.playbetwincliente.Principal.enviarCorreos(Principal.java:422)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at com.example.sergio.playbetwincliente.Principal.consePremios(Principal.java:388)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at android.view.View$1.onClick(View.java:3818)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at android.view.View.performClick(View.java:4438)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at android.view.View$PerformClick.run(View.java:18422)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at android.os.Looper.loop(Looper.java:136)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5045)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-28 16:42:06.895 1992-1992/com.example.sergio.playbetwincliente W/System.err: at dalvik.system.NativeStart.main(Native Method)
Uso las libreia javax.mail, additionnal y activation
Y con el permiso de internet activado ya que lo uso para otra parte del proyecto