0

I have a project with Jhipster ( Spring Boot ) and I need to add as an attachment to an email that generated an image.

The problem is that I do not know where I should locate the image inside the back-end folders or how to make a relative reference from Java so that it works both in development and in production

HttpResponse<String> response = 
            Unirest.post("https://api.infobip.com/email/1/send")
            .header("Authorization", "Basic xxxx=")
            .header("Accept", "application/json")
            .field("from", "xxx Notifications <notifications-noreply@xxxx.com>", "text/plain")
            .field("to", "joseluis.xxx@xxx.com", "text/plain")
            .field("replyTo", "xxx@xxx.com", "text/plain")
            .field("subject", "Prueba Full", "text/plain")
            .field("text", "text prueba full", "text/plain")
            .field("html", s, "text/plain")
            .field("attachment", new File("/MI_IMAGEN.JPG"))
            .field("bulkId", "cusotmBulkId", "text/plain")
            .field("intermediateReport", "true", "text/plain")
            .field("notifyUrl", "https://www.example.com/email/advanced", "text/plain")
            .field("notifyContentType", "application/json", "text/plain")
            .field("callbackData", "DLR callback data", "text/plain").asString();

It is this line:

field("attachment", new File("/MI_IMAGEN.JPG"))

I would need to take my image located in a route that I can access in a relative way both in development and in production.

msmolcic
  • 6,407
  • 8
  • 32
  • 56
Jose
  • 1,779
  • 4
  • 26
  • 50

1 Answers1

0

Don't create anything inside build/ folder as it is used by build tool(gradle or maven) to compile and package your project. It's similar to target/ folder for maven.

Put your mail related images and html templates inside src/main/resources/mails/ folder.

Alien
  • 15,141
  • 6
  • 37
  • 57