将表单数据发送到电子邮件

时间:2014-01-18 08:57:11

标签: android

我创建了一个包含3个edittext和3个微调器的简单表单,我想通过点击按钮将收集的所有数据发送到特定的电子邮件。我已将所有数据存储在textview(tv)中。我希望在发送电子邮件时,所有textview数据都显示在电子邮件中。 下面是我用于电子邮件的代码:

 Intent mEmail = new Intent(Intent.ACTION_SEND);
mEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{ "abc@gmail.com"});
mEmail.putExtra(Intent.EXTRA_SUBJECT, "subject");
mEmail.putExtra(Intent.EXTRA_TEXT, "message"+tv);
// prompts to choose email client
mEmail.setType("message/rfc822");
startActivity(Intent.createChooser(mEmail, "Choose an email client to send your")); 

3 个答案:

答案 0 :(得分:4)

Intent mEmail = new Intent(Intent.ACTION_SEND);
mEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{ "abc@gmail.com"});
mEmail.putExtra(Intent.EXTRA_SUBJECT, "subject");
mEmail.putExtra(Intent.EXTRA_TEXT, "message"+tv.getText());
// prompts to choose email client
mEmail.setType("message/rfc822");
startActivity(Intent.createChooser(mEmail, "Choose an email client to send your"));

答案 1 :(得分:3)

点击按钮可以这样写:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail}); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject"); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, tv.getText().toString());
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

如果你想在附件中发送图像,你可以像这样写:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
emailIntent.setType("application/image");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{strEmail}); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject"); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, tv.getText().toString());
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///mnt/sdcard/Myimage.jpeg"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

答案 2 :(得分:0)

以上答案非常有效。除了向EXTRA_TEXT添加更多行之外,请使用“ \ n”。例如:

  emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"This is a line of text followed by the text from a TextView\n" + ATextView.getText().toString());