简体   繁体   English

如何在Android邮件中将字符串作为html附件发送?

[英]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. 使用intent以如下方式发送电子邮件..如果您想添加一些字符串作为附件,则必须使用.html ext将内容保存到某个目录中,然后您可以将其作为附件添加到电子邮件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..."));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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