Issue
I'm trying to send email with mailgun and attaching two files or more with this email:
public static JsonNode sendComplexMessage() throws UnirestException {
HttpResponse<JsonNode> request = Unirest.post("https://api.mailgun.net/v3/" + YOUR_DOMAIN_NAME + "/messages")
.basicAuth("api", API_KEY)
.queryString("from", "Excited User <[email protected]>")
.queryString("to", "[email protected]")
.queryString("cc", "[email protected]")
.queryString("bcc", "[email protected]")
.queryString("subject", "Hello")
.queryString("text", "Testing out some Mailgun awesomeness!")
.queryString("html", "<html>HTML version </html>")
.field("attachment", new File("/temp/folder/test.txt"))
.asJson();
return request.getBody();
This example is from Mailgun Docs, but it send just single file. I need to send multiple emails.
Any help is appreciated.
Solution
instead of putting a single file object ,put an arrayList of Files and it's gonna to work like this :
.field("attachment", Arrays.asList(file1,file2))
you can create a list,iterate over it by loop and then send it
List<File> listFiles=new ArrayList<>();
// fill it
.field("attachment", listFiles)
Answered By - Mikhail Fayez
Answer Checked By - Robin (JavaFixing Admin)