0

我有一个 Jhipster ( Spring Boot ) 项目,我需要将其作为附件添加到生成图像的电子邮件中。

问题是我不知道应该在后端文件夹中的哪个位置找到图像,或者如何从 Java 中进行相对引用,以便它在开发和生产中都可以使用

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

就是这一行:

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

我需要将我的图像放置在我可以在开发和生产中以相对方式访问的路线中。

4

1 回答 1

0

不要在 build/ 文件夹中创建任何内容,因为构建工具(gradle 或 maven)使用它来编译和打包您的项目。它类似于 maven 的 target/ 文件夹。

将与邮件相关的图像和 html 模板放在 src/main/resources/mails/ 文件夹中。

于 2018-11-16T12:14:27.007 回答