public boolean sendMail(EmailMessage emailMessage) { boolean result=false; try { // Generate Spring MIME message and send. // Get system properties Properties properties = System.getProperties(); if(ServerUtil.isWindows()) properties.setProperty(EMAIL_SMTP_HOSTNAME_WIN, smtpHostName); else properties.setProperty(EMAIL_SMTP_HOSTNAME_LINUX, smtpHostName); Session session = Session.getDefaultInstance(properties); MimeMessage mimeMessage=new MimeMessage(session); //MimeMessage mimeMessage=javaMailSender.createMimeMessage(); mimeMessage.setFrom(new InternetAddress(emailMessage.getSender())); mimeMessage.addRecipient(RecipientType.TO, new InternetAddress(emailMessage.getReceiver())); mimeMessage.setSubject(emailMessage.getSubject()); mimeMessage.setContent(emailMessage.getContent(), "text/html; charset=utf-8"); Transport.send(mimeMessage); //javaMailSender.send(mimeMessage); result=true; } catch (Exception ex) { ex.printStackTrace(); logger.error(ex.getMessage()); } return result; }
Leave a Reply