在android中使用Microsoft Exchange帐户发送邮件

时间:2014-02-11 12:49:27

标签: android email

我已经制作了一个在后台发送邮件的应用程序。当我使用gmail帐户作为发件人帐户时,它工作正常。但是当我使用微软交换帐户并根据微软帐户设置主机和端口但仍然显示像logcat中的错误。我正在关注this链接

我已多次搜索无法获得任何解决方案,

发送邮件的代码:

_host = webmail1.xyz.com; // default smtp server 
_port = 443; // default smtp port 
_sport = 443; // Security port


Properties props = _setProperties(); 

Session session = Session.getInstance(props, this); 

      MimeMessage msg = new MimeMessage(session); 

      msg.setFrom(new InternetAddress(_from)); 

      InternetAddress[] addressTo = new InternetAddress[_to.length]; 
      for (int i = 0; i < _to.length; i++)
      { 
        addressTo[i] = new InternetAddress(_to[i].trim()); 
      } 
        msg.setRecipients(MimeMessage.RecipientType.TO, addressTo); 

      msg.setSubject(_subject); 
      msg.setSentDate(new Date()); 

      // setup message body 
      BodyPart messageBodyPart = new MimeBodyPart(); 
      messageBodyPart.setText(_body); 
      _multipart.addBodyPart(messageBodyPart); 

      // Put parts in message 
      msg.setContent(_multipart); 

      // send email 

      Transport.send(msg); 

 private Properties _setProperties() 
 { 
Properties props = new Properties(); 

props.put("mail.smtp.host", _host); 

if(_debuggable) { 
  props.put("mail.debug", "true"); 
} 

if(_auth) { 
  props.put("mail.smtp.auth", "true"); 
} 

props.put("mail.smtp.port", _port); 
props.put("mail.smtp.starttls.enable","true");

props.put("mail.smtp.socketFactory.port", _sport); 
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); 
props.put("mail.smtp.socketFactory.fallback", "true");

return props; 
}

logcat的:

02-11 18:10:51.170: W/System.err(2130): javax.mail.MessagingException: Could not connect to SMTP host: webmail1.xyz.com, port: 443;
02-11 18:10:51.170: W/System.err(2130):   nested exception is:
02-11 18:10:51.170: W/System.err(2130):     javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
02-11 18:10:51.170: W/System.err(2130):     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
02-11 18:10:51.170: W/System.err(2130):     at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
02-11 18:10:51.170: W/System.err(2130):     at javax.mail.Service.connect(Service.java:310)
02-11 18:10:51.170: W/System.err(2130):     at javax.mail.Service.connect(Service.java:169)
02-11 18:10:51.170: W/System.err(2130):     at javax.mail.Service.connect(Service.java:118)
02-11 18:10:51.170: W/System.err(2130):     at javax.mail.Transport.send0(Transport.java:188)
02-11 18:10:51.170: W/System.err(2130):     at javax.mail.Transport.send(Transport.java:118)
02-11 18:10:51.170: W/System.err(2130):     at com.xyz.Main.Mail.send(Mail.java:123)
02-11 18:10:51.170: W/System.err(2130):     at com.xyz.Fragments$SendMail.doInBackground(DownloadTab.java:634)
02-11 18:10:51.170: W/System.err(2130):     at com.xyz.Fragments$SendMail.doInBackground(DownloadTab.java:1)
02-11 18:10:51.170: W/System.err(2130):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-11 18:10:51.170: W/System.err(2130):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
02-11 18:10:51.170: W/System.err(2130):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
02-11 18:10:51.170: W/System.err(2130):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
02-11 18:10:51.170: W/System.err(2130):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
02-11 18:10:51.170: W/System.err(2130):     at java.lang.Thread.run(Thread.java:856)
02-11 18:10:51.170: W/System.err(2130): Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
02-11 18:10:51.170: W/System.err(2130):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:381)
02-11 18:10:51.170: W/System.err(2130):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl$SSLInputStream.<init>(OpenSSLSocketImpl.java:636)
02-11 18:10:51.170: W/System.err(2130):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.getInputStream(OpenSSLSocketImpl.java:607)
02-11 18:10:51.170: W/System.err(2130):     at com.sun.mail.smtp.SMTPTransport.initStreams(SMTPTransport.java:1449)
02-11 18:10:51.170: W/System.err(2130):     at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1366)
02-11 18:10:51.170: W/System.err(2130):     ... 15 more
02-11 18:10:51.170: W/System.err(2130): Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
02-11 18:10:51.170: W/System.err(2130):     at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:276)
02-11 18:10:51.170: W/System.err(2130):     at org.apache.harmony.xnet.provider.jsse.TrustManagerImpl.checkServerTrusted(TrustManagerImpl.java:197)
02-11 18:10:51.170: W/System.err(2130):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.verifyCertificateChain(OpenSSLSocketImpl.java:584)
02-11 18:10:51.180: W/System.err(2130):     at org.apache.harmony.xnet.provider.jsse.NativeCrypto.SSL_do_handshake(Native Method)
02-11 18:10:51.180: W/System.err(2130):     at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:378)
02-11 18:10:51.180: W/System.err(2130):     ... 19 more
02-11 18:10:51.180: W/System.err(2130): Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
02-11 18:10:51.180: W/System.err(2130):     ... 24 more
02-11 18:10:51.211: W/EGL_emulation(2130): eglSurfaceAttrib not implemented

0 个答案:

没有答案