我有 "Click to Download Invoice" link 的邮件,但我想将此 PDF 作为我邮件中的附件。使用 Springboot Java
I have Mail with "Click to Download Invoice" link But I want this PDF As a attachment in my Mail. Using Springboot Java
我正在创建一个 Link 并将其作为点击下载按钮附加到电子邮件,但现在我想在电子邮件中附加该 PDF 而不是点击下载。
这里没有 spring-boot 的特定内容。
您可以将 pdf 附加到电子邮件中,为此您需要 2 个 MimeBodyPart,一个用于邮件正文,一个用于附件:
Multipart multipart = new MimeMultipart();
MimeBodyPart messageBodyPart = new MimeBodyPart();
String message = "file attached. ";
messageBodyPart.setText(message, "utf-8", "html");
multipart.addBodyPart(messageBodyPart);
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
attachmentBodyPart.attachFile(new File(filePath+"/"+fileName), "application/pdf", null);
multipart.addBodyPart(attachmentBodyPart);
mail.setContent(multipart);
我正在创建一个 Link 并将其作为点击下载按钮附加到电子邮件,但现在我想在电子邮件中附加该 PDF 而不是点击下载。
这里没有 spring-boot 的特定内容。
您可以将 pdf 附加到电子邮件中,为此您需要 2 个 MimeBodyPart,一个用于邮件正文,一个用于附件:
Multipart multipart = new MimeMultipart();
MimeBodyPart messageBodyPart = new MimeBodyPart();
String message = "file attached. ";
messageBodyPart.setText(message, "utf-8", "html");
multipart.addBodyPart(messageBodyPart);
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
attachmentBodyPart.attachFile(new File(filePath+"/"+fileName), "application/pdf", null);
multipart.addBodyPart(attachmentBodyPart);
mail.setContent(multipart);