android javax邮件消息传递异常无法连接到smtp主机网络无法访问

android javax邮件消息传递异常无法连接到smtp主机网络无法访问,android,jakarta-mail,socketexception,Android,Jakarta Mail,Socketexception,我是Android开发的新手,尝试开发一个简单的应用程序,使用javax mail自动发送电子邮件。我尝试了几种用于SSL和TSL(端口号465和587)的代码,并添加了各自的属性。但它仍然会返回错误无效的IPv6类型或来自…的代码,邮件异常,无法连接到smtp主机,无法访问网络…。任何人都可以帮我解决问题。 我在下面添加我的代码片段: 主要活动: public class MainActivity extends Activity { Button b; @Override

我是Android开发的新手,尝试开发一个简单的应用程序,使用javax mail自动发送电子邮件。我尝试了几种用于SSL和TSL(端口号465和587)的代码,并添加了各自的属性。但它仍然会返回错误
无效的IPv6类型或来自…的代码,邮件异常,无法连接到smtp主机,无法访问网络…
。任何人都可以帮我解决问题。 我在下面添加我的代码片段:

主要活动:

public class MainActivity extends Activity {

    Button b;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
        .permitAll().build();

    StrictMode.setThreadPolicy(policy);
        b=(Button)findViewById(R.id.button1);
        b.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                new SendSync().execute();

            }
        });
    }


    public class SendSync extends AsyncTask<Void, Void, Void>
    {

        String error;
        @Override
        protected Void doInBackground(Void... params) {
            // TODO Auto-generated method stub..

            try {   
              GMailSender sender = new GMailSender("xyz@gmail.com", "pqrst");
              sender.sendMail("This is Subject",   
                      "This is Body",   
                      "xyz@gmail.com",   
                      "abcd@gmail.com");  

          } catch (Exception e) {   
              error=e.getMessage();
              Log.e("SendMail", e.getMessage(), e);   
              System.out.println("exception "+e);

          }
            return null; 


        }

        @Override
        protected void onPostExecute(Void result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            if(error!=null)
            {
                Toast.makeText(getApplicationContext(), "ERROR!!!", Toast.LENGTH_LONG).show();
                System.out.println("exception "+error);
            }


        }   
    }
以下是我收到的logcat消息:

02-20 11:43:38.804: I/System.out(31376): propertyValue:true
02-20 11:43:38.805: I/System.out(31376): [socket][4] connection smtp.gmail.com/2404:6800:4003:c00::6d:587;LocalPort=54051(0)
02-20 11:43:38.805: I/System.out(31376): [CDS]connect[smtp.gmail.com/2404:6800:4003:c00::6d:587] tm:90
02-20 11:43:38.805: D/Posix(31376): [Posix_connect Debug]Process com.example.mailtest :587 
02-20 11:43:38.822: I/dhcpcd(5854): dhcpcd[5855]: invalid IPv6 type or code from fe80::f63e:61ff:fe48:4fd1
02-20 11:43:38.823: I/System.out(31376): [socket][5:54051] exception
02-20 11:43:38.823: I/System.out(31376): [CDS]close[54051]
02-20 11:43:38.823: I/System.out(31376):mailsender exception javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
02-20 11:43:38.823: I/System.out(31376):   nested exception is:
02-20 11:43:38.824: I/System.out(31376):    java.net.ConnectException: failed to connect to smtp.gmail.com/2404:6800:4003:c00::6d (port 587) after 90000ms: isConnected failed: ENETUNREACH (Network is unreachable)
02-20 11:43:38.828: I/NotificationService(492): enqueueToast pkg=com.example.mailtest callback=android.app.ITransientNotification$Stub$Proxy@42bb7948 duration=1

互联网连接了吗?您在AndroidManifest
中是否具有此权限看起来您从不知道他们在做什么的人那里复制并粘贴了代码。你的代码有很多问题,尽管没有一个能解释你所遇到的错误。这段代码到底在哪里运行?在安卓手机中?我从某个人推荐的用于在安卓应用程序中发送电子邮件的stackoverflow站点获得此代码片段,我创建了示例应用程序,在尝试在安卓设备上运行时出现此错误。手机已连接到互联网,并且已添加了上述权限。
02-20 11:43:38.804: I/System.out(31376): propertyValue:true
02-20 11:43:38.805: I/System.out(31376): [socket][4] connection smtp.gmail.com/2404:6800:4003:c00::6d:587;LocalPort=54051(0)
02-20 11:43:38.805: I/System.out(31376): [CDS]connect[smtp.gmail.com/2404:6800:4003:c00::6d:587] tm:90
02-20 11:43:38.805: D/Posix(31376): [Posix_connect Debug]Process com.example.mailtest :587 
02-20 11:43:38.822: I/dhcpcd(5854): dhcpcd[5855]: invalid IPv6 type or code from fe80::f63e:61ff:fe48:4fd1
02-20 11:43:38.823: I/System.out(31376): [socket][5:54051] exception
02-20 11:43:38.823: I/System.out(31376): [CDS]close[54051]
02-20 11:43:38.823: I/System.out(31376):mailsender exception javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
02-20 11:43:38.823: I/System.out(31376):   nested exception is:
02-20 11:43:38.824: I/System.out(31376):    java.net.ConnectException: failed to connect to smtp.gmail.com/2404:6800:4003:c00::6d (port 587) after 90000ms: isConnected failed: ENETUNREACH (Network is unreachable)
02-20 11:43:38.828: I/NotificationService(492): enqueueToast pkg=com.example.mailtest callback=android.app.ITransientNotification$Stub$Proxy@42bb7948 duration=1