how to send mail to an email id in android? - android

In my project i have to send mail to company id.First i tried code with my email id. but its not showing anything.my code is here
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { "my emailid used here" };
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
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);
Log.e("name","msg sent success fully");
in my logcat i saw "msg sent success fully" message also. but i didnt get any mail in my mail id.
am i did any wrong code or am i need to add any permissions in manifest file.

Your code seems fine except there is no need to use "android.content." and there is no FLAG_ACTIVITY_NEW_TASK What should happen is that your email program should start with these data already entered. Have you setup your email client on that device?
Here is a code example that works and sends an image selected from a gallery as an attachment:
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("image/png");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + mUrls[imageSelected].toString()));
startActivity(i);

Related

Android Activity: ACTION_SEND

when using ACTION_SEND to send emails, is there a way to check if result was successful?
here is my code sample:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { "abc#xyz.com" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Subject of the Mail");
emailIntent.putExtra( android.content.Intent.EXTRA_TEXT,
"This is my sample Mail");
startActivity(Intent.createChooser(emailIntent, "Email:"));
Based on this posting: Get Mail Sent Notification in onActivityResult "Android" it sounds like the problem is that there is no guarantee that the client responsible for handling the intent is going to setActiviyResult, so there's no one way to get it. You'll have to check to see if the client that is handling the intent will send back a status.

Android not prompting me apps with email Capability

I'm trying to make a app, that takes information of some sort, then i want it to email that information to my gmail. I have found working code but when i load it onto my phone and run it and got all the info loaded into the app,and click the email, from what i understand its suppose to filter apps(on my phone) that are capable to send the email but I'm not getting anything, even though i have the default Email app that comes on the phone and i have Gmail.
public void Done(View view) {
Intent email = new Intent(Intent.ACTION_SENDTO); // it's not ACTION_SEND
email.putExtra(Intent.EXTRA_EMAIL, "some#gmail.com");
email.putExtra(Intent.EXTRA_SUBJECT, "OverStock Changes");
email.putExtra(Intent.EXTRA_TEXT, printReport());
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Email"));
}
See answer for ACTION_SENDTO for sending an email
If you use ACTION_SENDTO, putExtra() does not work to add subject and
text to the intent. Use setData() and the Uri tool add subject and
text.
This example works for me:
// ACTION_SENDTO filters for email apps (discard bluetooth and others)
String uriText =
"mailto:youremail#gmail.com" +
"?subject=" + URLEncoder.encode("some subject text here") +
"&body=" + URLEncoder.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"));
Otherwise use ACTION_SEND as mentioned:
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"mail#mail.com","mail2#mail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT,"subject");
intent.putExtra(Intent.EXTRA_TEXT, "mail content");
startActivity(Intent.createChooser(intent, "title of dialog"));

Android Email Intent Issue

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

Adding the Body in the Email in Android

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

How to send Mail from Android app

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

Categories

Resources