class MailService {

	private MimeMessagePreparator buildMimeMessagePreparator(String cc,String from, List<String> to, String subject, String mailMessageUrlOrBody, Map<String, Object> placeholderValues, final String attachmentUrl, final Boolean isPlainMessage) {
		MimeMessagePreparator messagePreparator = mimeMessage -> {
			MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true);
			messageHelper.setFrom(from);
			
			if(!StringUtils.isEmpty(cc)){
			messageHelper.setCc(cc);
			}
			
			String[] toMailList = to.toArray(new String[to.size()]);
			messageHelper.setTo(toMailList);
			messageHelper.setSubject(subject);
			if(StringUtils.isNotEmpty(attachmentUrl) && isHttpUrl(attachmentUrl)) {
				URL url = new URL(attachmentUrl);
				String filename = url.getFile();
				byte fileContent [] = getFileContent(url);
				messageHelper.addAttachment(filename, new ByteArrayResource(fileContent));
			}
			String content = StringUtils.EMPTY;
			if(isPlainMessage) {
				content = mailContentBuilderService.buildPlainTextMail(mailMessageUrlOrBody, placeholderValues);
			} else {
				if(!isHttpUrl(mailMessageUrlOrBody)) {
					File template = new ClassPathResource("templates/".concat(mailMessageUrlOrBody).concat(".html")).getFile();
					content = mailContentBuilderService.buildPlainTextMail(FileUtils.readFileToString(template, "UTF-8"), placeholderValues);
				} else {
					String mailBody = mailContentBuilderService.getRemoteMailContent(mailMessageUrlOrBody);
					content = mailContentBuilderService.buildPlainTextMail(mailBody, placeholderValues);
				}
			}
			messageHelper.setText(content, true);
		};
		return messagePreparator;
	}

	@Autowired public  MailService(JavaMailSender mailSender, MailContentBuilderService mailContentBuilderService);

}