从我的Android应用程序发送带有网络附件的电子邮件

时间:2012-02-16 08:57:15

标签: android

我想创建一个发送带附件的电子邮件的应用程序(从中选择文件 SD卡/画廊)。我试图找到相关的代码,但我没有找到它。
请提供一些代码。
以下是发送邮件的示例代码 提前致谢。

  Sendbtn.setOnClickListener(new View.OnClickListener()
   {

    @Override
    public void onClick(View v) 
    {
        // TODO Auto-generated method stub
        String TO,CC,Subject,Body,URL;
        try
        {
        URL = Environment.getExternalStorageDirectory()
                .getAbsolutePath() + "/temp";

                File file = new File(URL);
                if (!file.exists())
                file.mkdirs();
                URL = URL + "/report.html";
                createFile();
                //
                Log.i(getClass().getSimpleName(), "send  task - start");
                //
                final Intent emailIntent = new Intent(
                android.content.Intent.ACTION_SEND);
                //
                TO=(TOEText.getText().toString());
                CC=(CCEText.getText().toString());
                Subject=(SubjectEText.getText().toString());
                URL=(BrowseEText.getText().toString());
                Body=(BodyEText.getText().toString());

                //
                emailIntent.setType("plain/text");

                emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                new String[] { TO });

                emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, Subject);

                emailIntent.putExtra(Intent.EXTRA_STREAM,
                Uri.parse("file://" + URL));

                emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Body);

                //this.startActivity(Intent
                //.createChooser(emailIntent, "Send mail..."));

            }
            catch (Throwable t)
            {
                Message(t);

            }
        }
   });
}

2 个答案:

答案 0 :(得分:2)

请点击下面,

请访问此image-attachmentlink。 Links有示例代码供您参考。

答案 1 :(得分:2)

嗨,这里只有stackoverflow有ans。,做一些R& D并尝试一些代码。 好的,检查一下这个。我发布的how to getAuth token and send email in background?希望它对您有所帮助。

相关问题