JAVA
네이버 메일 발송 테스트
KIMSG
2017. 7. 21. 13:58
네이버 메일 테스트 입니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | package kr.co.goodcodes.servlet; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class NaverMailTest { public static void main(String args[]) throws MessagingException{ // 메일 관련 정보 String host = "smtp.naver.com"; final String username = "네이버아이디"; final String password = "비밀번호"; int port=465; // 메일 내용 String recipient = "수신자"; String subject = "네이버를 사용한 발송 테스트입니다."; String body = "내용 무"; Properties props = System.getProperties(); props.put("mail.smtp.host", host); props.put("mail.smtp.port", port); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.ssl.enable", "true"); props.put("mail.smtp.ssl.trust", host); Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { String un=username; String pw=password; protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(un, pw); } }); session.setDebug(true); //for debug Message mimeMessage = new MimeMessage(session); mimeMessage.setFrom(new InternetAddress("발신자 정보")); mimeMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(recipient)); mimeMessage.setSubject(subject); mimeMessage.setText(body); Transport.send(mimeMessage); } } | cs |