【问题标题】:Javax Mail File Path for Attachment附件的 Javax 邮件文件路径
【发布时间】:2014-10-02 12:31:51
【问题描述】:

我知道这可能是一个业余问题:

MimeMultiPart 消息中附加文件作为附件的任何可定位文件夹的路径是什么?

我已经按照一个例子来制作这个:

MimeBodyPart imagePart = new MimeBodyPart();
imagePart.attachFile("logo.jpg");
imagePart.setContentID("<" + cid + ">");
imagePart.setDisposition(MimeBodyPart.INLINE);
content.addBodyPart(imagePart);

但是当调用 Transport.send 时,我得到了 file not found 异常。

基本上,我可以将“logo.png”放在我的项目结构中的哪个位置,以便此静态方法可以访问它?

【问题讨论】:

    标签: java path classpath email-attachments jakarta-mail


    【解决方案1】:

    您当前的代码看起来与工作目录相关。如果您只想移动文件,则需要将其放置在工作目录中。您可以通过获取规范路径来确定。

    new File("logo.jpg").getCanonicalPath()
    

    此代码返回您需要放置 logo.jpg 的路径。

    【讨论】:

      猜你喜欢
      • 2013-02-19
      • 2018-07-25
      • 2020-11-07
      • 2015-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      相关资源
      最近更新 更多