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
Post a Comment