如何将HTML文件作为电子邮件内容发送?

时间:2018-02-27 09:48:11

标签: android html-email intentfilter android-assets

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

我正在使用按钮onclick listener方法通过我的应用程序发送电子邮件。我有一个html文件,我想作为电子邮件内容发送,文件的位置存储在资产中的www文件夹中。如何将该电子邮件作为电子邮件内容发送?

2 个答案:

答案 0 :(得分:1)

使用以下代码发送带文件附件的邮件

java\
 -jar node_modules/google-closure-compiler/compiler.jar\
 --compilation_level=ADVANCED\
 --process_common_js_modules\
 --dependency_mode=STRICT\
 --js_output_file='./dist/compiled.js'\
 --module_resolution=NODE\
 --entry_point=./src/module\
 --js='./src/**.js'\
 --js='./node_modules/isarray/**.js'\
 --js='./node_modules/isarray/**package.json'

答案 1 :(得分:0)

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)));
相关问题