简体   繁体   中英

Send html file as email body content using android intent

I have an ecommerce app that shares the product as html document. Using this code I can send the product.html as attachment. I want to send the html document as the body of email instead of attachment.

Here is my code :

private void sendEmail(Context context, String emailTo, String emailCC,
                       String subject, String emailText, List<String> filePaths) {

    final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
    emailIntent.setType(TEXT_HTML);
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{emailTo});
    emailIntent.putExtra(android.content.Intent.EXTRA_CC, new String[]{emailCC});
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);

    ArrayList<Uri> fileUris = new ArrayList<Uri>();
    for (String file : filePaths) {
        File fileIn = new File(file);
        Uri uri = Uri.fromFile(fileIn);
        fileUris.add(uri);
    }

    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, fileUris);
    context.startActivity(Intent.createChooser(emailIntent, context.getString(R.string.send_by_email))); }

Anything that needs to go into the body can be set into your intent this way eg puts your builds version name as the body of the email. You can replace that with your html content. Have never tried that personally, You might need some conversion.

emailIntent.putExtra(Intent.EXTRA_TEXT, BuildConfig.VERSION_NAME);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM