我如何附上一个txt文件到电子邮件? [英] How do I attach a .txt file to an email?

查看:177
本文介绍了我如何附上一个txt文件到电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是相当新的Andr​​oid和我有电子邮件中的问题。我想一个文本文件附加到电子邮件,并进行发送,但是当我做,我得到一个文件过大的错误。这是我第一次在应用程序中设置电子邮件,有人可以请帮助?

code:

  myfile文件=新的文件(Environment.getExternalStorageDirectory()+/test.txt);
    URI URI = Uri.fromFile(MYFILE);    意图emailIntent =新意图(android.content.Intent.ACTION_SEND);    字符串aEmailList [] = {person@gmail.com};
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,aEmailList);
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,测试);
    emailIntent.setType(纯/文);
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,这是一个测试。);
    emailIntent.putExtra(Intent.EXTRA_STREAM,URI);    startActivity(emailIntent);


解决方案

  

您好,试试这个。


 公共无效的sendmail(字符串[]邮寄地址,的String [] CC,主题字符串,字符串的身体,字符串attachmentFilePath)
{
    意图emailIntent =新意图(android.content.Intent.ACTION_SEND);
    emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    emailIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);    emailIntent.setType(纯/文);    如果(邮寄地址!= NULL)
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,邮寄地址);
    如果(CC!= NULL)
    emailIntent.putExtra(android.content.Intent.EXTRA_CC,CC);
    如果(主题!= NULL)
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,学科);
    如果(身体!= NULL)
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromHtml(体));
    如果(邮寄地址!= NULL)
    emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse(文件://+ attachmentFilePath));    context.startActivity(emailIntent);
}

I am fairly new to android and I am having a problem with the email. I am trying to attach a text file to an email and send it, but when I do I get a "File too large" error. This is my first time setting up email within an application, can someone please help?

Code:

    File myFile = new File(Environment.getExternalStorageDirectory() + "/test.txt");
    Uri uri = Uri.fromFile(myFile);

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);  

    String aEmailList[] = { "person@gmail.com" };    
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);     
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");  
    emailIntent.setType("plain/text");  
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is a test.");
    emailIntent.putExtra(Intent.EXTRA_STREAM, uri);

    startActivity(emailIntent);   

解决方案

Hello , try this one.

public void sendMail(String[] mailTo,String[] cc,String subject, String body, String attachmentFilePath)
{
    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    emailIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);

    emailIntent.setType("plain/text");

    if(mailTo!=null)
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,mailTo);
    if(cc!=null)
    emailIntent.putExtra(android.content.Intent.EXTRA_CC, cc);
    if(subject!=null)
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
    if(body!=null)
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
    if(mailTo!=null)
    emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+attachmentFilePath));

    context.startActivity(emailIntent); 
}

这篇关于我如何附上一个txt文件到电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆