附件的Javax邮件文件路径
我理解这可能是一个业余问题: 在附件的Javax邮件文件路径,java,path,classpath,email-attachments,jakarta-mail,Java,Path,Classpath,Email Attachments,Jakarta Mail,我理解这可能是一个业余问题: 在MimeMultiPart消息中将文件作为附件附加到任何可定位文件夹的路径是什么 我遵循了一个示例来生成: MimeBodyPart imagePart = new MimeBodyPart(); imagePart.attachFile("logo.jpg"); imagePart.setContentID("<" + cid + ">"); imagePart.setDisposition(MimeBodyPart.INLINE); content
MimeMultiPart
消息中将文件作为附件附加到任何可定位文件夹的路径是什么
我遵循了一个示例来生成:
MimeBodyPart imagePart = new MimeBodyPart();
imagePart.attachFile("logo.jpg");
imagePart.setContentID("<" + cid + ">");
imagePart.setDisposition(MimeBodyPart.INLINE);
content.addBodyPart(imagePart);
MimeBodyPart imagePart=新的MimeBodyPart();
imagePart.attachFile(“logo.jpg”);
imagePart.setContentID(“”);
setDisposition(MimeBodyPart.INLINE);
content.addBodyPart(imagePart);
但在调用Transport.send时,我发现文件未找到异常
基本上,我可以将“logo.png”放在我的项目结构中的什么位置,这样就可以使用这种静态方法访问它?您当前的代码看起来是相对于工作目录的。如果您只想移动文件,则需要将其放置在工作目录中。您可以通过获取规范路径来确定这一点
new File("logo.jpg").getCanonicalPath()
此代码返回需要放置logo.jpg的路径