2
button2.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        String emailList[]= {"rufidennis@gmail.com"};
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("message/rfc822");
        intent.putExtra(Intent.EXTRA_EMAIL,emailList);
        intent.putExtra(Intent.EXTRA_SUBJECT,"Email Subject");          
        intent.putExtra(Intent.EXTRA_TEXT,"file:///android_asset/www/sample3.html");                     
        startActivity(Intent.createChooser(intent,"Choice email APP"));
    }
});

I am using buttons onclick listener method to send an email via my app. I have an html file which i want to send as an email content, the location of file is stored in www folder inside assets. How can i send that email as an email content??

Komal12
  • 3,340
  • 4
  • 16
  • 25
dennisrufigill
  • 379
  • 1
  • 3
  • 14
  • 1
    Possible duplicate of [Sending Email with attachment from Asset folder](https://stackoverflow.com/questions/30252769/sending-email-with-attachment-from-asset-folder) – Zeero0 Feb 27 '18 at 09:52

2 Answers2

2

Use the below code to sent a mail with file attachement

String filename="file.html"; 
File filelocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), filename);
Uri path = Uri.fromFile(filelocation); 
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"asd@gmail.com"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
// the attachment
emailIntent .putExtra(Intent.EXTRA_STREAM, path);
// the mail subject
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
Léo R.
  • 2,620
  • 1
  • 10
  • 22
1
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType(TEXT_HTML);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,emailTo);
emailIntent.putExtra(android.content.Intent.EXTRA_CC,emailCC);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT,"file:///android_asset/www/sample3.html");

context.startActivity(Intent.createChooser(emailIntent, context.getString(R.string.send_by_email)));
Nits24
  • 11
  • 1