Reputation: 1292
I have an ordinary code to send text email via Intent, using the emulator. The problem I have is that the 'Compose' activity of the Email client - I use an ICS AVD - comes-up when the startActivity() is executed. All the fields are correctly filled-in and I must click on 'Send' to wrap-up the process. After that, the control goes back to my application UI and the email is correctly delivered to destination. What should I do to have done the sending smoothly in the background, without popping-up the emulator's Email application? Here is my code:
public class AppPilot extends Application {
...
private static Context context;
...
@Override
public void onCreate() {
super.onCreate();
context = this;
}
....
/**
* Send an Email
* @param emailAddress
* @param emailObject
* @param emailBody
*/
public static void sendEmailCoupon(String emailAddress, String emailSubject,
String emailBody) {
String emailadd[] = { emailAddress };
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(Intent.EXTRA_EMAIL, emailadd);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
emailIntent.setType("plain/text");
emailIntent.putExtra(Intent.EXTRA_TEXT, emailBody);
context.startActivity(emailIntent);
}
Upvotes: 1
Views: 1455
Reputation: 1292
Here is the answer for those looking for in the future, in case this post will be clicked before the original one: Sending Email in Android using JavaMail API without using the default/built-in app. Basically, first download the 3 jar files - mail.jar (URI: http://javamail-android.googlecode.com/files/mail.jar); activation.jar (URI: http://javamail-android.googlecode.com/files/activation.jar); additional.jar (URI: http://javamail-android.googlecode.com/files/additionnal.jar) into the /libs folder of your Eclipse project. Then right click on each of them and reference with Build Path > Add to Build Path. Create a separate 'Email' class and follow at 100% the code as posted in the link above by 'droopie'. Using JavaMail is required so that to bypass the security design principles or Android as an application container. HTH
Upvotes: 2