I am working on sending my message data on my email Id.I have made a mainActivity class containing an editText (for emailId) and a Button. Another class is BroadcastReceiver
I create open source library for this. Usage is very simple:
BackgroundMail bm = new BackgroundMail(context);
bm.setGmailUserName("yourgmail@gmail.com");
bm.setGmailPassword("yourgmailpassword");
bm.setMailTo("receiver@gmail.com");
bm.setFormSubject("Subject");
bm.setFormBody("Body");
bm.send();
With this permissions
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
You can download it here: https://github.com/kristijandraca/BackgroundMailLibrary
This is one way of sending emails by using explicit email intent but this will not send in background
Intent sendemai = new Intent(Intent.ACTION_SEND);
sendemai.putExtra(Intent.EXTRA_EMAIL,
new String[] { toaddress });
sendemai.putExtra(Intent.EXTRA_CC,
new String[] { emailadd });
sendemai.putExtra(Intent.EXTRA_SUBJECT, sub);
sendemai.putExtra(Intent.EXTRA_TEXT, body);
// need this to prompts email client only
sendemai.setType("message/rfc822");
startActivity(Intent.createChooser(payment_request,
"Select email application"));
If you want to send in background then you need to provide some of user secure credentials.See Here
In android, You can send Email with explicit email intent however it will show a email screen and will not allow to send data in background.
To send data in background, you can use java mail api to send the mail.
Take a look on this http://www.tutorialspoint.com/java/java_sending_email.htm