0

I want to create one application which send email with attachment(select file from
SD card/gallery). I try to find relevent code but i did'nt find it.
Please provide me some code.
Here is sample code for sending mail.
Thanks in advance.

  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);

            }
        }
   });
}
OnkarDhane
  • 1,450
  • 2
  • 14
  • 24
Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160

2 Answers2

2

Just go through below,

Please visit this image-attachment, link. Links has the example code for your reference.

Community
  • 1
  • 1
Altaaf
  • 527
  • 3
  • 11
2

Hi here only on stackoverflow there are ans., Do some R&D and try some code. OK, check this ans. which i have posted how to getAuth token and send email in background? hope it will helpful for you.

Community
  • 1
  • 1
OnkarDhane
  • 1,450
  • 2
  • 14
  • 24