1

i want to send email from my application,how can write code for send email from my application,have any setup for email?,anybody knows,please give sample code for me..

Thanks All

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

@Thanks samuch,how can i attach image file in email
I've added the details in my answer. Also check the referenced google group thread.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.