email - Adding attachment in android using Java Mail -


i trying add attachments email send using javamail. can send email without attachment error when try attach file.

03-28 18:07:36.735: e/sendmail(6703): null 03-28 18:07:36.735: e/sendmail(6703): java.lang.nullpointerexception 03-28 18:07:36.735: e/sendmail(6703):   @ com.example.email.gmailsender.addattachment(gmailsender.java:95) 03-28 18:07:36.735: e/sendmail(6703):   @ com.example.email.mainactivity$1$1.run(mainactivity.java:28) 

here method use attach file.

public void addattachment(string filename) throws exception {         bodypart messagebodypart = new mimebodypart();         datasource source = new filedatasource(filename);         messagebodypart.setdatahandler(new datahandler(source));         messagebodypart.setfilename(filename);         _multipart.addbodypart(messagebodypart);           message.setcontent(_multipart);     } 

and call in main activity.

sender.addattachment("/storage/extsdcard/dcim/camera/photo.jpg"); 

do think there wrong path of file, if how can correct path.

your trying attach file reading external storage. so, make sure have below permission in manifest.

<uses-permission      android:name="android.permission.write_external_storage" > 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -