I am sending an email with attachments! Everything is in order, but there is one problem. The files that I added to the email body are named "FULL PATH". sending as ...
class SendEmailAsyncTask extends AsyncTask <Void, Void, Boolean> { @Override protected Boolean doInBackground(Void... params) { { Context context = getApplicationContext(); Mail m = new Mail("**** a@gmail.com ", "te****mail"); String[] toArr = {"te**** all@yan ****"}; m.setTo(toArr); m.setFrom("t**** il.ya@gmail.com "); m.setSubject("TESTING"); m.setBody(" test"); try { String path = "/mnt/sdcard/qwe"; File fileDir = new File( path ); String[] _files = fileDir.list(); for ( int i = 0 ; i < _files.length ; i++ ) { _files[i] = path + "/"+ _files[i]; // _files[i] = path + "/"+ _files[i].substring(_files[i].lastIndexOf("/")); m.addAttachment(_files[i]); Log.v("list sending", _files[i]); Log.v("list sending", _files[i].substring(_files[i].lastIndexOf("/"))); } if(m.send()) { for ( int i = 0 ; i < _files.length ; i++ ) { Log.v("test mail result", "success"); } } else { Log.v("test mail result", "fail"); } } catch(Exception e) { Log.v("test mail result", "error while sending"); } } return null; } }
Sending Log ...
02-07 11:18:15.542: V/list sending(18255): /mnt/sdcard/qwe/1233.txt 02-07 11:18:15.542: V/list sending(18255): /1233.txt 02-07 11:18:15.542: V/list sending(18255): /mnt/sdcard/qwe/123.txt 02-07 11:18:15.542: V/list sending(18255): /123.txt 02-07 11:18:15.552: V/list sending(18255): /mnt/sdcard/qwe/12333.txt 02-07 11:18:15.552: V/list sending(18255): /12333.txt 02-07 11:18:15.722: D/dalvikvm(18255): GC_FOR_MALLOC freed 3564 objects / 349496 bytes in 33ms 02-07 11:18:15.722: I/global(18255): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required. 02-07 11:18:16.222: I/SSLSocketFactory(18255): Using factory org.apache.harmony.xnet.provider.jsse.OpenSSLSocketFactoryImpl@4 006ed60 02-07 11:18:17.084: D/NativeCrypto(18255): SSL_OP_NO_SSLv3 is set 02-07 11:18:18.562: I/global(18255): Default buffer size used in BufferedOutputStream constructor. It would be better to be explicit if an 8k buffer is required. 02-07 11:18:18.562: I/global(18255): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required. 02-07 11:18:19.152: I/global(18255): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required. 02-07 11:18:27.687: V/test mail result(18255): success
How can I get only the file names in my attachments?
source share