2017-03-01 21 views
0

私は 電子メールクライアントを使用して電子メールを送信するにはどうすればよいですか?

    1. ツーは

    2. 自分のプライマリメールを取得しようとしていますが、受信者のアドレスとしてのプライマリ電子メールを設定するので、私は電子メールを送信することができます

    3. 自分自身に

    これはどのようにあります私のプライマリEメールが届きます。

    Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ 
          Account[] accounts = AccountManager.get(getBaseContext()) 
            .getAccounts(); 
          for (Account account : accounts) { 
           if (emailPattern.matcher(account.name).matches()) { 
            String possibleEmail = account.name; 
            Toast.makeText(this, possibleEmail, Toast.LENGTH_LONG) 
              .show(); 
           } 
          } 
    

    が、これは私がEXTRA_EMAIL私の主な電子メールを与えるにはどうすればよい

    Intent i = new Intent(Intent.ACTION_SEND); 
          i.setType("message/rfc822"); 
          i.putExtra(Intent.EXTRA_EMAIL, 
            new String[] { "[email protected]" }); 
          i.putExtra(Intent.EXTRA_SUBJECT, "subject of email"); 
          i.putExtra(Intent.EXTRA_TEXT, "body of email"); 
          try { 
           startActivity(Intent.createChooser(i, "Send mail...")); 
          } catch (android.content.ActivityNotFoundException ex) { 
           Toast.makeText(Main.this, 
             "There are no email clients installed.", 
             Toast.LENGTH_SHORT).show(); 
          } 
    

    メール:送信する方法ですか?

  • +0

    、単にコピー&ペーストので、あなたがその地域で何かをアーカイブする場合、プログラミングは本当に悪い方法です。 – Divers

    +0

    「AccountManager」がユーザに使用可能な電子メールアドレスを持つ必要はないことに注意してください。 – CommonsWare

    +0

    @Divers too bad、私はアスリートで、私は音楽を必要とするだけの理由でこれをやっています。私はあなたのプレイリストを失うことはありませんので、私は私自身に電子メールで私のスポットプロファイルを保存し、後で私は無制限の試用版を取得し、この保存されたプロファイルを取得することができますアプリを作っています。 – joey

    答えて

    0

    ソリューション:

    あなたが言語の少なくとも基本的な理解を持っている必要があります
    String possibleEmail = null; 
        Pattern emailPattern = Patterns.EMAIL_ADDRESS; // API level 8+ 
        Account[] accounts = AccountManager.get(getBaseContext()) 
          .getAccounts(); 
        for (Account account : accounts) { 
         if (emailPattern.matcher(account.name).matches()) { 
          possibleEmail = account.name; 
          Toast.makeText(this, possibleEmail, Toast.LENGTH_LONG) 
            .show(); 
         } 
        } 
    
        Intent i = new Intent(Intent.ACTION_SEND); 
        i.setType("message/rfc822"); 
        i.putExtra(Intent.EXTRA_EMAIL, new String[]{possibleEmail}); 
        i.putExtra(Intent.EXTRA_SUBJECT, "subject of email"); 
        i.putExtra(Intent.EXTRA_TEXT, "body of email"); 
        try { 
         startActivity(Intent.createChooser(i, "Send mail...")); 
        } catch (android.content.ActivityNotFoundException ex) { 
         Toast.makeText(Main.this, 
           "There are no email clients installed.", 
           Toast.LENGTH_SHORT).show(); 
        } 
    
    関連する問題