Sandip Armal Patil
Sandip Armal Patil

Reputation: 5905

Sending Email with attachment in network from my Android app

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

            }
        }
   });
}

Upvotes: 0

Views: 1868

Answers (2)

OnkarDhane
OnkarDhane

Reputation: 1460

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.

Upvotes: 2

Altaaf
Altaaf

Reputation: 527

Just go through below,

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

Upvotes: 2

Related Questions