Karma5
Karma5

Reputation: 273

Sending Form data to email

I have created a simple form with 3 edittext and 3 spinner and I want to send all the data collected to a specific email on a click of button. I have stored all the data in a textview(tv). I want that when sending an email all the textview data is shown in email. Heres the code i am using for email:

 Intent mEmail = new Intent(Intent.ACTION_SEND);
mEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{ "[email protected]"});
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")); 

Upvotes: 3

Views: 3770

Answers (3)

PhilipS
PhilipS

Reputation: 379

The answers above work great. In addition to add more lines to the EXTRA_TEXT use "\n". For example:

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

Upvotes: 0

Mehul Ranpara
Mehul Ranpara

Reputation: 4255

You can write like this on click on button:

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

And if you want to send image in attachement you can write like this :

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

Upvotes: 3

Digvesh Patel
Digvesh Patel

Reputation: 6533

Intent mEmail = new Intent(Intent.ACTION_SEND);
mEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{ "[email protected]"});
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"));

Upvotes: 4

Related Questions