Untitled
unknown
java
2 years ago
2.4 kB
12
Indexable
private GenericResponse sendEmail(Mail mail, String template) {
try {
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(5, TimeUnit.MINUTES)
.writeTimeout(5, TimeUnit.MINUTES)
.readTimeout(5, TimeUnit.MINUTES)
.build();
log.info("sendEmail SEND_EMAIL_FROM: {}", SEND_EMAIL_FROM);
String soap =
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:skk=\"http://10.3.6.246:5555/skkmigas.ws.inbound.common:wsCommon\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <skk:sendNotificationViaEmail>\n" +
" <to>" + encodeValue(mail.getTo()) +"</to>\n" +
" <cc></cc>\n" +
" <bcc></bcc>\n" +
" <subject>"+ encodeValue(mail.getSubject()) +"</subject>\n" +
" <bodyEmail>" + encodeValue(getEmailContent(mail, template)) +"</bodyEmail>\n" +
" <from>" + encodeValue(SEND_EMAIL_FROM) +"</from>\n" +
" </skk:sendNotificationViaEmail>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
MediaType mediaType = MediaType.parse("text/xml");
RequestBody body = RequestBody.create(mediaType, soap);
log.info("Request Soap", soap);
log.info("Request Body", body);
log.info("sendEmail", SEND_EMAIL_URL);
Request request = new Request.Builder()
.url(SEND_EMAIL_URL)
.post(body)
.addHeader("SOAPAction", "\"#sendNotificationViaEmail\"")
.addHeader("content-type", "text/xml")
.build();
log.info("sendEmail request: ", request);
Response response = client.newCall(request).execute();
log.info("sendEmail response: ", response);
return objectMapper.readValue(response.body().string(), GenericResponse.class);
} catch (IOException e) {
log.error("failed to send email with subject: {} to: {} with exception: {}", mail.getSubject(), mail.getTo(), e.getMessage(), e);
throw new RuntimeException(e);
}
}Editor is loading...
Leave a Comment