lomza
lomza

Reputation: 9736

Problem with sending an email

I wrote the following code for sending E-Mail,

Intent sendIntent = new Intent(Intent.ACTION_SEND);
                     sendIntent.setType("plain/text");
                     sendIntent.putExtra(Intent.EXTRA_EMAIL,emailAddress);
                     sendIntent.putExtra(Intent.EXTRA_SUBJECT,emailSubject);
                     sendIntent.putExtra(Intent.EXTRA_TEXT,emailBody);
                     startActivity(Intent.createChooser(sendIntent,
                     "Choose email Application"));

But when the EMail application opens I have "To", "Subject", and "Content" fields empty. What is wrong with my code?

Upvotes: 0

Views: 294

Answers (2)

Andrew Mackenzie
Andrew Mackenzie

Reputation: 5745

You have a typo:

sendIntent.setType("plain/text");

should be

sendIntent.setType("text/plain");

but in fact better is

sendIntent.setType( "message/rfc822" );

Upvotes: 0

Josnidhin
Josnidhin

Reputation: 12504

The emailAddress variable has to be a String Array of emails.

Check emailSubject and emailBody are of type String. You can also try sendIntent.setType("message/rfc822");

Upvotes: 1

Related Questions