spring mail codings
public class EmailService {
@Autowired
private JavaMailSender sender;
@Autowired
private Configuration config;
public ICUser sendEmail(ICUser user, Map<String, Object> model) {
// User response = new User();
MimeMessage message = sender.createMimeMessage();
try {
// set mediaType
MimeMessageHelper helper = new MimeMessageHelper(message, MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED,
StandardCharsets.UTF_8.name());
// add attachment
// helper.addAttachment("logo.jpg", new ClassPathResource("logo.jpg"));
Template t = config.getTemplate("email-template.ftl");
String html = FreeMarkerTemplateUtils.processTemplateIntoString(t, model);
helper.setTo(user.getEmail());
helper.setText(html, true);
helper.setSubject("OnClick Info Team");
helper.setFrom("[email protected]");
sender.send(message);
}
}