请教一个问题希望高手给解决一下万分感谢我在使用javamail时带附件的只要附件是英文路径就能正常上传,一旦含有中文就提示如:d:????/?????/文件名(系统找不到指定的路径)还有就是,...
请教一个问题希望高手给解决一下 万分感谢
我在使用javamail 时 带附件的 只要附件是 英文路径 就能正常上传,
一旦含有中文就提示如 : d:????/?????/文件名(系统找不到指定的路径)
还有就是,内容中还有中文的再邮箱里显示的都是乱码
主要代买如下:
public boolean send()
{
try {
Properties props=new Properties();
props.put("mail.smtp.host", SMTPHost);
props.put("mail.smtp.auth", "true");
SmtpAuth auth=new SmtpAuth();
auth.setAccount(user, password);
Session mailsession=Session.getDefaultInstance(props,auth);
mailsession.setDebug(true);
Message message=new MimeMessage(mailsession);
message.setSubject(subject);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setHeader("X-Priority", "1");
Multipart container=new MimeMultipart();
BodyPart textbodypart=new MimeBodyPart();
textbodypart.setContent(content, "text/html;charset=gb2312");
container.addBodyPart(textbodypart);
BodyPart filebodypart=new MimeBodyPart();
FileDataSource fds=new FileDataSource(filename);
System.out.println("--------");
System.out.println(fds.getContentType());
System.out.println(fds.getInputStream());
System.out.println(fds.toString());
System.out.println(fds.getClass());
System.out.println(fds.getFile().getAbsolutePath());
System.out.println(fds.getFile().getCanonicalPath());
System.out.println("--------");
filebodypart.setDataHandler(new DataHandler(fds));
String attachName=fds.getName();
attachName=new String(attachName.getBytes("gb2312"),"ISO8859-1");
filebodypart.setFileName(attachName);
container.addBodyPart(filebodypart);
message.setContent(container);
message.saveChanges();
Transport transport=mailsession.getTransport("smtp");
transport.connect(SMTPHost, user, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
return true;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
以下是我想看看 能不能正常找到路径: 可惜提示找不到系统路径,关键就是路径有中文,请问如何解决谢谢
System.out.println("--------");
System.out.println(fds.getContentType());
System.out.println(fds.getInputStream());
System.out.println(fds.toString());
System.out.println(fds.getClass());
System.out.println(fds.getFile().getAbsolutePath());
System.out.println(fds.getFile().getCanonicalPath());
System.out.println("--------")
展开