I am Creating a Link and attaching that to Email as Click to download Button but Now I want to Attach that PDF in Email Instead of Click to Download.
Nothing specific to spring-boot here.
You can attach pdf to email and for that you need 2 MimeBodyParts, one for the main message body and one for the attached file:
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);