I have Mail with “Click to Download Invoice” link But I want this PDF As a attachment in my Mail. Using Springboot Java [closed]

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");

    MimeBodyPart attachmentBodyPart = new MimeBodyPart();
    attachmentBodyPart.attachFile(new File(filePath+"/"+fileName), "application/pdf", null);

Leave a Reply

Your email address will not be published. Required fields are marked *