unable to send email from my application - android

I have a requirement that I need to send email from my application, I am using below code to send email...
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("Text/Plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{abc#gmail.com});
intent.putExtra(Intent.EXTRA_TEXT, "hello..");
startActivity(Intent.createChooser(intent, email_chooser_title));
The above code launching the email composer. But after I press on send button , I can see one toast message "Message Sending" , But my message not sent.
pl. help me to figure out where I did wrong in this, or let me know if any alternative to solve this.. thanks.

Intent i = new Intent(Intent.ACTION_SEND);
//i.setType("text/plain"); //use this line for testing in the emulator
i.setType("message/rfc822") ; // use from live device
i.putExtra(Intent.EXTRA_EMAIL, new String[]{"test#gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT,"subject goes here");
i.putExtra(Intent.EXTRA_TEXT,"body goes here");
startActivity(Intent.createChooser(i, "Select email application."));

Related

Android : how to post a tweet only by Tweet (not by Direct Message?)

Here is the code I'm using to share a tweet :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.setPackage("com.twitter.android");
intent.putExtra(Intent.EXTRA_TEXT, "My text");
startActivity(intent);
This opens a popup enabling the user to share it by Tweet or by Direct Message, when I only want it to be shared by tweet. How can I do that?
Thank you very much.
Try this :
Intent tweet = new Intent(Intent.ACTION_VIEW);
tweet.setData(Uri.parse("http://twitter.com/?status=" + Uri.encode(message)));// replace message by your string message
startActivity(tweet);

Android Studio: Email fill on gmail?

I've integrated code to send an email from my app.i have search on that and found the solution which i have already integrated but it didn't work for me.
Basically, The code include the text and the subject but does not add the email address (on which we have to send email) in gmail.
Can any one help me?
protected void sendEmail (String strtwi){
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, "projectmyangel#hotmail.com");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Spread More Cheer!");
emailIntent.putExtra(Intent.EXTRA_TEXT, strtwi);
emailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(emailIntent, "Email"));
}
change this line
emailIntent.putExtra(Intent.EXTRA_EMAIL, "projectmyangel#hotmail.com");
with
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"myEmail#gmail.com"});
if above didn't solve your issue try below:
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"myEmail#gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(intent, "Contact Me..."));
}
Android API does not supply the assignment of the email address (on which to send mail).
The intent is just a message that sent to the application you select in Intent.createChooser(emailIntent, "Email") and fill in the necessary columns refer to the information you have given.
Since the email address that the mail sent from differs from one user to another, it is better to choose them in the email application the user select rather than in your application.

how to send mail to an email id in 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);

Messaging and email intents in Android?

I've searched Google for this, but have only found similar examples--not exactly what I need. I simply need to start messaging (SMS) and email intents from my app with their "to" fields already populated. So I need to send a number with the sms intent and an email address with the email intent. Any help would be appreciated.
For the e-mail part :
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"foo#bar.com"});
emailIntent.setType("text/plain");
startActivity(Intent.createChooser(emailIntent, "Send a mail ..."));
from Only Email apps to resolve an Intent
String recepientEmail = ""; // either set to destination email or leave empty
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:" + recepientEmail));
startActivity(intent);
will filter out all non-email applications.

Android: Separate intents for email & SMS

I have an app that has two buttons – one for email & one for SMS. Depending on the button pressed I want to email or else SMS a certain text. I have coded the email button and it is working fine. The problem is that the dialog box that pops-up gives an option of e-mail or Messaging the text. I want to separate out the two, so that when the user presses email, only the options of email is there, and when the user presses SMS, only the option of Messaging is there.
Here is the code that I have tried.
private void sendEmail(){
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient#example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Subject of the message");
i.putExtra(Intent.EXTRA_TEXT , "Body of the message");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
Basically there seems to be a single intent Intent.ACTION_SEND for both emails & Messaging.
Any way to separate them out?
You can launch the Messaging application with a prepopulated message like this:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "The SMS text");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
or do something like this to just send it straightaway, without presenting the Messaging app:
Uri uri = Uri.parse("smsto:0800000123");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
startActivity(it);
String to use for sending email only is:
email.setType("message/rfc822");

Categories

Resources