[JAVA 로만 이용(]
public static void main(String[] args) { JavaMailSender sender = getSender(); /* SimpleMailMessage msg = new SimpleMailMessage(); msg.setTo("ddakker@~"); msg.setSubject("제목"); msg.setFrom("ddakker@~"); msg.setText("내용"); sender.send(msg); */ MimeMessage msg = sender.createMimeMessage(); MimeMessageHelper helper; try { helper = new MimeMessageHelper(msg, true, "UTF-8"); helper.setSubject("제목"); helper.setTo("ddakker@~"); helper.setFrom("ddakker@~"); helper.setText("내용", true); sender.send(msg); } catch (MessagingException e) { e.printStackTrace(); } } private static JavaMailSenderImpl getSender(){ JavaMailSenderImpl sender = new JavaMailSenderImpl(); sender.setHost("도메인 및 아이피"); sender.setUsername("계정 아이디"); sender.setPassword("비밀번호"); Properties props = new Properties(); props.put("mail.smtp.auth", "true"); sender.setJavaMailProperties(props); return sender; }
[JAVA 와 Spring DI 와 함께 이용]
${mailHost} ${mailAdminId} ${mailAdminPwd} true
JavaMailSender sender = (JavaMailSender) getBean("sender"); MimeMessage msg = sender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(msg, true, "UTF-8"); helper.setSubject(p_subject); helper.setTo(p_to); helper.setFrom(p_from); helper.setText(p_message, true); sender.send(msg);