简体   繁体   中英

How to send a String as html attachment in Android mail?

我想将字符串作为html附件附加到android邮件中,我该如何实现。请帮助我提供一个摘要来完成此操作。非常感谢。

Use intent to send email like below way .. and if u want to add some string as attachment u have to save that content into some directory with .html ext and later u can add it as attachment into email intent. [This code for idea it may need few modification as per ur app requirement..]

    String emailText = "email message";
    final Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setType("plain/text");
    emailIntent.setType("message/rfc822");
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "demo@gmail.com"});
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Hi");       
    emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);

    String attachContent = "<html> content </html>";
    /* this method u have to write, to save the string into html file 
    into cache or any other dir */
      saveFile(getCacheDir()+"/attach.html", attachContent );
      File file = new File(root, getCacheWebDir()+"/attach.html");
      Uri uri  = Uri.fromFile(file);
      emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
      this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));

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