-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple attachement in FormData #14
Comments
Hi @micky008, |
Thank you for the answer. |
Maybe you can even share it ;) |
i need to find first, but it's ok if i find i post here the solution |
Thank you |
The solution is very dirty... I use unirest public class MyEmailAttachment {
byte[] content;
String name;
}
public class MailGunService implements IMailerService {
private static final Logger logger = Logger.getLogger(MailGunService.class);
@Override
public void send(List<User> recipient, List<User> ccU, String subject, String message, List<MyEmailAttachment> attachments, String mailingList) throws Exception {
List<String> to = Collector.collect(recipient, "email");
List<String> cc = Collector.collect(ccU, "email");
HttpResponse<JsonNode> request = null;
String baseUrl = getKey(Configuration.MAILGUN_BASEURL);
String domain = getKey(Configuration.MAILGUN_DOMAIN);
String apiKey = getKey(Configuration.MAILGUN_API_KEY);
String from = getKey(Configuration.MAILGUN_FROM_SENDER);
String url = baseUrl + "/v3/" + domain + "/messages";
MultipartBody body = Unirest.post(url)
.basicAuth("api", apiKey)
.field("from", from)
.field("to", to)
.field("cc", cc)
.field("subject", subject)
.field("html", message);
for (MyEmailAttachment mya : attachments) {
body.field("attachment", new ByteArrayInputStream(mya.content), mya.name);
}
request = body.asJson();
if (request.getBody().getObject().getString("id") != null) {
for (User user : recipient) {
logger.info("Email sent to " + (user != null ? user.getName() : "null") + (ccU != null && !ccU.isEmpty() ? " (cc to " + ccU + ")" : "") + (StringUtils.isNotEmpty(mailingList) ? " from Mailing List " + mailingList : ""));
}
}
request.ifFailure(error -> {
logger.error(error.getStatusText());
if (error.getParsingError().isPresent()) {
Exception e = error.getParsingError().get();
logger.error(e, e);
}
});
}
private String getKey(String key) {
return DAO.getConfigurationDao().getConfiguration(key);
}
} |
@micky008 Multiple FormData attachment support was added in v1.0.5. |
Hello,
I've a problem with FormData...
How to put many attachment with FormData...
All attachments is created in memory and i don't want to create and delete a File for sending my email.
Thank you
it's possible to make this ?
The text was updated successfully, but these errors were encountered: