i want to send email from my application,how can write co开发者_JS百科de for send email from my application,have any setup for email?,anybody knows,please give sample code for me..
Thanks All
You can either use Android's Intent system to launch the native email client on the phone. You can pre-populate the fields. User intervention is required to send the email. Code would be something like:
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, recipients);
email.putExtra(Intent.EXTRA_TEXT, "First Email from Android");
email.putExtra(Intent.EXTRA_SUBJECT, "Subject & Predicate");
email.setType("message/rfc822");
startActivity(email);
You can also send attachments, see this thread for details.
EDIT:
Use android.content.Intent.EXTRA_STREAM
and pass to it the URI of your file image file.
For e.g: if you have your a image file on your sdcard you can say:
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,
Uri.parse("file://"+Environment.getExternalStorageDirectory().getAbsolutePath()+"/mybitmap.png"))
If you want to send an email programmatically, without user intervention you can use the JavaMail port for Android. I haven't tried it myself but see the following thread for details: Sending Email using JavaMail
精彩评论