发送邮件时,我在log cat上遇到以下异常。
01-13 14:32:36.559: DEBUG/SntpClient(68): request time failed: java.net.SocketException: Address family not supported by protocol
01-13 14:34:41.831: WARN/System.err(1753): javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
01-13 14:34:41.831: WARN/System.err(1753): nested exception is:
01-13 14:34:41.839: WARN/System.err(1753): java.net.SocketTimeoutException: Connection timed out
01-13 14:34:41.839: WARN/System.err(1753): at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
01-13 14:34:41.839: WARN/System.err(1753): at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
01-13 14:34:41.849: WARN/System.err(1753): at javax.mail.Service.connect(Service.java:288)
01-13 14:34:41.849: WARN/System.err(1753): at javax.mail.Service.connect(Service.java:169)
01-13 14:34:41.849: WARN/System.err(1753): at javax.mail.Service.connect(Service.java:118)
01-13 14:34:41.849: WARN/System.err(1753): at javax.mail.Transport.send0(Transport.java:188)
01-13 14:34:41.859: WARN/System.err(1753): at javax.mail.Transport.send(Transport.java:118)
01-13 14:34:41.859: WARN/System.err(1753): at com.enthrall.GMailSender.sendMail(GMailSender.java:75)
01-13 14:34:41.859: WARN/System.err(1753): at com.enthrall.MailSenderActivityActivity$1.onClick(MailSenderActivityActivity.java:24)
01-13 14:34:41.869: WARN/System.err(1753): at android.view.View.performClick(View.java:2485)
01-13 14:34:41.869: WARN/System.err(1753): at android.view.View$PerformClick.run(View.java:9080)
01-13 14:34:41.869: WARN/System.err(1753): at android.os.Handler.handleCallback(Handler.java:587)
01-13 14:34:41.869: WARN/System.err(1753): at android.os.Handler.dispatchMessage(Handler.java:92)
01-13 14:34:41.869: WARN/System.err(1753): at android.os.Looper.loop(Looper.java:123)
01-13 14:34:41.879: WARN/System.err(1753): at android.app.ActivityThread.main(ActivityThread.java:3647)
01-13 14:34:41.879: WARN/System.err(1753): at java.lang.reflect.Method.invokeNative(Native Method)
01-13 14:34:41.879: WARN/System.err(1753): at java.lang.reflect.Method.invoke(Method.java:507)
01-13 14:34:41.879: WARN/System.err(1753): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-13 14:34:41.879: WARN/System.err(1753): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-13 14:34:41.899: WARN/System.err(1753): at dalvik.system.NativeStart.main(Native Method)
01-13 14:34:41.899: WARN/System.err(1753): Caused by: java.net.SocketTimeoutException: Connection timed out
01-13 14:34:41.899: WARN/System.err(1753): at org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
01-13 14:34:41.909: WARN/System.err(1753): at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:357)
01-13 14:34:41.909: WARN/System.err(1753): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:204)
01-13 14:34:41.909: WARN/System.err(1753): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:437)
01-13 14:34:41.909: WARN/System.err(1753): at java.net.Socket.connect(Socket.java:983)
01-13 14:34:41.919: WARN/System.err(1753): at java.net.Socket.connect(Socket.java:926)
01-13 14:34:41.919: WARN/System.err(1753): at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
01-13 14:34:41.919: WARN/System.err(1753): at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:163)
01-13 14:34:41.919: WARN/System.err(1753): at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1359)
01-13 14:34:41.919: WARN/System.err(1753): ... 19 more
01-13 14:37:36.589: DEBUG/SntpClient(68): request time failed: java.net.SocketException: Address family not supported by protocol
01-13 14:41:02.749: INFO/dalvikvm(68): Jit: resizing JitTable from 4096 to 8192
这是我设置的属性,我还提到了清单文件中的Internet权限。我改变了什么sholud,以便邮件可以通过模拟器发送
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", mailhost);
//props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");
session = Session.getDefaultInstance(props, this);
答案 0 :(得分:0)
您是否在应用中获得了互联网权限?
android.permission.INTERNET