【发布时间】:2014-07-22 09:24:04
【问题描述】:
您好,我正在通过 android 应用程序发送邮件。我在我的应用程序中导入邮件库和激活库。
当我发送邮件已成功发送但附件没有发送。任何人都可以告诉我如何发送。
这是我的代码:
public synchronized void sendMail(String body, String recipients) throws Exception {
try{
MimeMessage message = new MimeMessage(session);
DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain"));
message.setSender(new InternetAddress("shankar.uclid@gmail.com"));
message.setSubject("Request For Claim");
MimeBodyPart messageBodyPart2=new MimeBodyPart(); // creating new MimeBodyPart object and setting DataHandler to this object
String filename="file:///android_asset/code.js"; //you can change according to your choice
DataSource source=new FileDataSource(filename);
messageBodyPart2.setDataHandler(new DataHandler(source));
messageBodyPart2.setFileName(filename);
Multipart multipart=new MimeMultipart();
multipart.addBodyPart(messageBodyPart2);
message.setContent(multipart);
message.setDataHandler(handler);
showLog("recepetent is "+recipients);
if (recipients.indexOf(',') < 0)
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("shankar.uclid@gmail.com"));
else
message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients));
Transport.send(message);
}catch(Exception e){
e.printStackTrace();
}
}
我不明白为什么我的附件没有收到。
谢谢
【问题讨论】:
-
这些链接没有使用 mail.jar、activation.jar。我想直接通过代码而不是任何提取。
标签: java android sendmail attachment email-attachments