我的問題是什麼?用JavaMail附加文件
我已經創建了SD形象,也將文件添加到DCIM相機..並沒有什麼..
我有這樣的錯誤: java.io.FileNotFoundException
這是我發送代碼:
Button addImage = (Button) findViewById(R.id.button1);
addImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Envialo m = new Envialo("[email protected]", "LOquillo97");
String[] toArr = {"[email protected]", "[email protected]"};
m.setTo(toArr);
m.setFrom("[email protected]");
m.setSubject("This is an email sent using my Mail JavaMail wrapper from an Android device.");
m.setBody("Email body. Testing from My APP");
try {
m.addAttachment("file:///sdcard/DCIM/Camera/test.jpg");
//Log.e("MailApp", "Attachment");
if(m.send()) {
Toast.makeText(ABC.this, "Email was sent successfully.", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ABC.this, "Email was not sent.", Toast.LENGTH_LONG).show();
}
} catch(Exception e) {
Toast.makeText(ABC.this, "There was a problem sending the email.", Toast.LENGTH_LONG).show();
Log.e("MailApp", "Could not send email", e);
}
}
});
這是我的目錄下載:
12-30 11:25:26.682: I/global(1342): Default buffer size used in BufferedOutputStream constructor. It would be better to be explicit if an 8k buffer is required.
12-30 11:25:26.682: I/global(1342): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
12-30 11:25:26.832: I/global(1342): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
12-30 11:25:27.852: E/MailApp(1342): Could not send email
12-30 11:25:27.852: E/MailApp(1342): javax.mail.MessagingException: IOException while sending message;
12-30 11:25:27.852: E/MailApp(1342): nested exception is:
12-30 11:25:27.852: E/MailApp(1342): java.io.FileNotFoundException: /sdcard/DCIM/Camera/test.jpg
12-30 11:25:27.852: E/MailApp(1342): at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:676)
12-30 11:25:27.852: E/MailApp(1342): at javax.mail.Transport.send0(Transport.java:189)
12-30 11:25:27.852: E/MailApp(1342): at javax.mail.Transport.send(Transport.java:118)
12-30 11:25:27.852: E/MailApp(1342): at org.cw.LLC.Envialo.send(Envialo.java:99)
12-30 11:25:27.852: E/MailApp(1342): at org.cw.LLC.ABC$1.onClick(ABC.java:30)
12-30 11:25:27.852: E/MailApp(1342): at android.view.View.performClick(View.java:2344)
12-30 11:25:27.852: E/MailApp(1342): at android.view.View.onTouchEvent(View.java:4133)
12-30 11:25:27.852: E/MailApp(1342): at android.widget.TextView.onTouchEvent(TextView.java:6510)
12-30 11:25:27.852: E/MailApp(1342): at android.view.View.dispatchTouchEvent(View.java:3672)
12-30 11:25:27.852: E/MailApp(1342): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
12-30 11:25:27.852: E/MailApp(1342): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
12-30 11:25:27.852: E/MailApp(1342): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
12-30 11:25:27.852: E/MailApp(1342): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
12-30 11:25:27.852: E/MailApp(1342): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712)
12-30 11:25:27.852: E/MailApp(1342): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202)
12-30 11:25:27.852: E/MailApp(1342): at android.app.Activity.dispatchTouchEvent(Activity.java:1987)
12-30 11:25:27.852: E/MailApp(1342): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1696)
12-30 11:25:27.852: E/MailApp(1342): at android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
12-30 11:25:27.852: E/MailApp(1342): at android.os.Handler.dispatchMessage(Handler.java:99)
12-30 11:25:27.852: E/MailApp(1342): at android.os.Looper.loop(Looper.java:123)
12-30 11:25:27.852: E/MailApp(1342): at android.app.ActivityThread.main(ActivityThread.java:4203)
12-30 11:25:27.852: E/MailApp(1342): at java.lang.reflect.Method.invokeNative(Native Method)
12-30 11:25:27.852: E/MailApp(1342): at java.lang.reflect.Method.invoke(Method.java:521)
12-30 11:25:27.852: E/MailApp(1342): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
12-30 11:25:27.852: E/MailApp(1342): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
12-30 11:25:27.852: E/MailApp(1342): at dalvik.system.NativeStart.main(Native Method)
12-30 11:25:27.852: E/MailApp(1342): Caused by: java.io.FileNotFoundException: /sdcard/DCIM/Camera/test.jpg
12-30 11:25:27.852: E/MailApp(1342): at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:231)
12-30 11:25:27.852: E/MailApp(1342): at java.io.FileInputStream.<init>(FileInputStream.java:80)
12-30 11:25:27.852: E/MailApp(1342): at javax.activation.FileDataSource.getInputStream(FileDataSource.java:110)
12-30 11:25:27.852: E/MailApp(1342): at javax.activation.DataHandler.writeTo(DataHandler.java:318)
12-30 11:25:27.852: E/MailApp(1342): at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1403)
12-30 11:25:27.852: E/MailApp(1342): at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:874)
12-30 11:25:27.852: E/MailApp(1342): at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:444)
12-30 11:25:27.852: E/MailApp(1342): at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:102)
12-30 11:25:27.852: E/MailApp(1342): at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:897)
12-30 11:25:27.852: E/MailApp(1342): at javax.activation.DataHandler.writeTo(DataHandler.java:330)
12-30 11:25:27.852: E/MailApp(1342): at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1403)
12-30 11:25:27.852: E/MailApp(1342): at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1745)
12-30 11:25:27.852: E/MailApp(1342): at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:636)
12-30 11:25:27.852: E/MailApp(1342): ... 25 more
哪裏沒有pressent?我已經在eclipse中創建了SDCARD ..並且還在DCIM文件夾中創建了該文件。問題是什麼? – Schotm 2011-12-30 21:29:37
如果您指定:/SDCARD/DCIM/Camera/test.jpg – 2011-12-30 21:35:23
我發現問題...是我的模擬器可以選擇妻子用戶信息..這會刪除我的照片.. – Schotm 2011-12-30 22:00:10