Adding attachments in java mail API android

I can send email by this code and email is send successfully
but the problem is that i want to attach picture to my email .

MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(""));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(reciep));
            message.setContent(txtmsg,"text/html; charset=utf-8");

Below is the method from which i can take picture and save it in myfolder .

 private void saveImage(byte[] arg0) {
 String root = Environment.getExternalStorageDirectory() + "/.MeraFolder";

File myDir = new File(root);
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String fname = timeStamp + ".jpg";

file = new File(myDir, fname);
if (file.exists()) {

Bitmap bitmap1 = BitmapFactory.decodeByteArray(arg0, 0, arg0.length);
FileOutputStream out;
try {
    out = new FileOutputStream(file);
    bitmap1.compress(Bitmap.CompressFormat.JPEG, 90, out);
} catch (FileNotFoundException e) {
} catch (IOException e) {


Now i have 2 questions
1) Is there a way that i can attach the recently taken picture in my email or is there any way that the picture i take is directly attached too my email .

2) When there is no internet connectivity the email gets failed ow can i over come this problem that when there is no internet connectivity the email gets on hold as soon as internet connectivity is available the email is sent .
Any help will be appreciated as i am new to android

Source: java

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.