簡體   English   中英

如何使用JavaMail API將電子郵件中的鏈接嵌入到電子郵件中附加的文件?

[英]How to embed a link in email message for file attached in email using JavaMail API?

我想使用JavaMail API將電子郵件中的鏈接嵌入到電子郵件中已附加的文件中。

例如,我正在發送帶有某些附件的電子郵件。 現在,我想為電子郵件中可用的所有文件嵌入鏈接。

您能幫我嗎?

我正在使用以下代碼在電子郵件中附加文件:

MimeBodyPart messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(attachFile);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(attachFileName);

設置附件如下代碼:

MimeBodyPart messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(attachFile);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setHeader("Content-ID","file");
messageBodyPart.setFileName(attachFileName);

在以上代碼中,Content-ID被定義為文件,可以在錨標記的href中用作參考:

<a href='cid:html'>link text</a>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM