我有一个邮件发送应用程序,它发送电子邮件和附件。除了附件部分外,这一切都很好。我正在使用此代码。但我不知道这段代码缺少什么或有什么问题。请帮忙。这是附件部分。
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);
}
在我的主要活动中,我正在使用
public final static String APP_PATH_SD_CARD = "/Images_Book/";
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + APP_PATH_SD_CARD;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String mailBody = "Email is send along with attachment";
Mail m = new Mail("FTP backup failed", mailBody);
try {
m.addAttachment(path);
m.send();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}