private Message createMessage(String content) { Message message = new MimeMessage(session); try { message.setFrom(new InternetAddress(config.getUsername())); message.setRecipients( Message.RecipientType.TO, InternetAddress.parse(config.getEmailToNotificate())); message.setSubject(SUBJECT); message.setContent(content, "text/html; charset=utf-8"); } catch (MessagingException e) { LOG.error("Error during message creating", e); } return message; }
private void initSession() { Properties props = new Properties(); props.put("mail.smtp.auth", config.isSmtpAuth()); props.put("mail.smtp.starttls.enable", config.isSmtpStarttls()); props.put("mail.smtp.host", config.getSmtpHost()); props.put("mail.smtp.port", config.getSmtpPort()); props.put("mail.smtp.ssl.trust", config.getSmtpHost()); username = config.getUsername(); session = Session.getInstance( props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, config.getPassword()); } }); }