I need to send an e-mail from my Android application. So, I send 2 parameters ( e-mail and subject) to the e-mail client app, but when app opens e-mail client, there is only subject parameter added, and email parameter is not set.
How I can fix this?
String getMail = email.toString();
Log.d("GET MAIL:",getMail);
String subject = "Subject";
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, getMail);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
// need this to prompts email client only
emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent,"Choose E-mail client:"));
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"me#gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From App");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Change emailIntent.putExtra(Intent.EXTRA_EMAIL, getMail);
to:
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{getMail});
getMail should be a string array...
Related
I am creating utility to send email. In my code i use chooser intent to choose email app to send email. It work perfectly but the problem is that if i use attachment file in this code using Uri then in chooser i choose G-mail, and then G-mail is stopped. If i send email without attachment it work good. Can any one solve my problem. Here is my code.
public void SendEmail() {
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setData(Uri.parse("mailto: "));
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL,to);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, body);
// intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Send Mail..."));
}
In this code a line is in comment. if i use this line then G-mail is stopped. I am using this line for file attachment. Help me please.
/**Use the below Code Snippet**/
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("vnd.android.cursor.dir/email");
String to[] = {""};
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + "Your URI"));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
Use this code it's works for me correctly:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = {"info#marutinandan.com"};
//String aEmailCCList[] = { "user3#fakehost.com","user4#fakehost.com"};
//String aEmailBCCList[] = { "user5#fakehost.com" };
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
// emailIntent.putExtra(android.content.Intent.EXTRA_CC, aEmailCCList);
// emailIntent.putExtra(android.content.Intent.EXTRA_BCC, aEmailBCCList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "your subject");
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "your message body.");
startActivity(emailIntent);
In Android Studio I wish to send an email on a button click. I am using the following code till I work out what is going on before I start changing thing.
String[] TO = {"ABC#yahoo.com.au"};
String[] CC = {"xyz#gmail.com"};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Some message added in here");
try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,
"There is no email client installed.", Toast.LENGTH_SHORT).show();
}
This works fine and well and shows up on my phone with the email content being as expected, however the email content, "Some message added in here" line is clearly hardcoded. I obviously wish to add in my own content by doing the following
String content = "Information I want to send";
emailIntent.putExtra(Intent.EXTRA_TEXT, content);
But for some reason the email content is blank. Why does is a string "content" recognised but a String variable x is not?
Check This Examples
By Looking at your code i only found problem in setting
emailIntent.setType(text/plain).
May Be you are using Gmail for sending mails(So you have to check second example).
Send Email (to Phone Email Client)
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "some#email.address" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail body");
startActivity(Intent.createChooser(intent, ""));
Send Email (to Gmail)
Gmail does not examine the extra Intent fields, so in order to use this intent, you need to use the Intent.ACTION_SENDTO and pass a mailto: URI with the subject and body URL encoded.
String uriText =
"mailto:youremail#gmail.com" +
"?subject=" + Uri.encode("some subject text here") +
"&body=" + Uri.encode("some text here");
Uri uri = Uri.parse(uriText);
Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setData(uri);
startActivity(Intent.createChooser(sendIntent, "Send email"));
I want to send the email from my android app. If i m using
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
It is opening skype,bluetooth along with the mail client
and if i use
Intent emailIntent = new Intent(android.content.Intent.ACTION_SENDTO);
then it is only opening mail client,but in the text body it is adding %20%20 when there is new line
Which approach is suitable to get only mail client and body of the mail containing new lines and spaces.
Try sending it as below:
String subject = "mail subject";
String body = "whatever the mail content is. may include html tags too";
Intent intMail = new Intent(Intent.ACTION_SEND);
intMail.setType("message/rfc822");
intMail.putExtra(Intent.EXTRA_SUBJECT, subject);
intMail.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
startActivity(Intent.createChooser(intMail, "Send Email..."));
Try to use this code. You can keep subject, body etc as optional. It only opens email client and gives right output.
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Body);
startActivity(Intent.createChooser(emailIntent, "Email:"));
I had developed the email sending functionality in my Application where I need to send the email with the specified subject. I have done that but I need that as soon as I click the Email Icon It sets some particular piece of Information in the Body part of the email format. It could be any information that I have with me.
Is it possible to set the data in the Email Body in android, I don't want to write anything in the Body of the mail.
Thanks,
DavidBrown
final Intent emailIntent = new Intent( android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "abc#gmail.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Email Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"Email Body");
startActivity(Intent.createChooser(
emailIntent, "Send mail..."));
Intent.EXTRA_TEXT is what you are looking for.
Try this
intent.putExtra(Intent.EXTRA_TEXT ,
"body of email -- add text what you want ");
This can be useful for you..
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"support#arboristapp.com"});
emailIntent.putExtra(Intent.EXTRA_CC, new String[]{""});
emailIntent.putExtra(Intent.EXTRA_BCC, new String[]{""});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject of email");
emailIntent.putExtra(Intent.EXTRA_TEXT, "This is test app");
startActivity(emailIntent);
Not very clear what exactly you want. But if you need to add text/data in email body use
intent.putExtra(Intent.EXTRA_TEXT, "This data will appear in email body");
I have developed a very simple Android app where user has to select items from the Spinners and type some texts in a Message box. Then the job is to SUBMIT. If the user tap on SUBMIT the whole selected data would send to a specific email address directly. After successful sending there comes a Dialog box showing some Thank You message. It should be mentioned here that I've used 4 Spinners and 1 Edittext box.
Now I'm looking for the code to SUBMIT button's action. Please help me out.
Thank in advance.
I have never written an email sending function in Android. However, the alternative way instead of sending the email through your app is to fire the intent to other email app.
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String receiver = "someone#somewhere.com";
String subject = "your email subject";
String body = "your email body";
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, receiver);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
startActivity(emailIntent);
Also, don't forget adding permission in your AndroidManifest.
I used it in my app. here is the code.
When multiple Application to send email handling it to others applications
startActivity(Intent.createChooser(emailIntent, "Send your email in:"));
Supplying Message Content
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { "user#gmail.com","user2#gmail.com" };
String aEmailCCList[] = { "user3#gmail.com","user4#gmail.com"};
String aEmailBCCList[] = { "user5#gmail.com" };
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
emailIntent.putExtra(android.content.Intent.EXTRA_CC, aEmailCCList);
emailIntent.putExtra(android.content.Intent.EXTRA_BCC, aEmailBCCList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My subject");
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "My message body.");
startActivity(emailIntent);