This question already has an answer here:
For my app, I have retrieved my message inbox/sent
. Now I want to send that retrieved data on my email address.how can it be? Is any authentication required for it? Also I have tried to download the authentication files (authentication.jar,mail.jar) but can't succeeded.
long currentTime = System.currentTimeMillis();
long pastThreeHour = currentTime - (AlarmManager.INTERVAL_HOUR * 3);
String[] selectionArgs = { "" + pastThreeHour, "" + currentTime };
Cursor cursor = contentResolver.query(uri, null, selection, selectionArgs, "date DESC");
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String number = cursor.getString(cursor.getColumnIndex("address")); // check for null
String date = cursor.getString(cursor.getColumnIndex("date")); // convert to date its long
String message_text = cursor.getString(cursor.getColumnIndex("body"));
String type = cursor.getString(cursor.getColumnIndex("type")); // check type and get names
// send email from here
sendSMSEmail(number, date, message_text, type);
}
}
cursor.close();
}
Yes, it is possible to send email in background use following code, to send email
and
You would be requiring activation.jar, additionnal.jar & mail.jar files
There is a library for Sending Email in Background which is working efficient. You can get the library from here Background Mail Library
Now import this library in your eclipse, and then go to project properties and add this library to your project. After all this process, just put these code in your project, and it will send email in background.
With this permissions
Update 1: Updated the Library name