下面的代码将调用服务以发送带有1个附件的邮件,我想添加更多附件。
private void sendMailWithAttachemnts(String url, Map<String, Object> requestPayload) {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
FileSystemResource file = new FileSystemResource(new File(invoiceServiceProperties.getInvoiceDir()+"\\"+requestPayload.get("MerchantName")+"_invoice.pdf"));
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
**body.add("files", file);** // i want to add multiple files here
body.add("to",requestPayload.get("mercahntEmailId"));
body.add("emailSubjectLine","Welcome Aboard");
body.add("emailBody","Welcome aboard.");
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.exchange(url,HttpMethod.POST, requestEntity, String.class);
logger.info("response : {}", response);
}