JAVA언어 javamail 587로 전송하기(whois mail) 천상의날개 2017. 6. 29. 11:12 java mail 전송 (javamail.jar ver 1.5.6) // Sender's email ID needs to be mentioned final String from = "test@test.com"; // Assuming you are sending email from localhost String host = "mail.test.com"; //587포트 Properties props = new Properties(); props.put("mail.smtp.host", host); //SMTP Host props.put("mail.smtp.port", "587"); //TLS Port props.put("mail.smtp.auth", "true"); //enable authentication props.put("mail.smtp.starttls.enable", "true"); //enable props.put("mail.smtp.ssl.trust", host); //465포트 /*Properties props= new Properties(); props.put("mail.smtp.host", host); props.put("mail.smtp.port", "465"); props.put("mail.smtp.starttls.enable","true"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.debug", "true"); props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.socketFactory.fallback", "false");*/ // Get the default Session object. //Session session = Session.getDefaultInstance(properties); Authenticator auth = new Authenticator() { //override the getPasswordAuthentication method protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(from, "test1234"); } }; Session session = Session.getInstance(props, auth); try { // Create a default MimeMessage object. MimeMessage message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(from)); // Set To: header field of the header. message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); // Set Subject: header field //message.setSubject("뎅장찌개는 과연 맛이?","utf-8"); message.setSubject("메일 테스트","utf-8"); // Create the message part BodyPart messageBodyPart = new MimeBodyPart(); // Fill the message messageBodyPart.setText("뎅장찌개 맛이 궁금함 알려주길 바람!"); // Create a multipar message Multipart multipart = new MimeMultipart(); // Set text message part multipart.addBodyPart(messageBodyPart); // Part two is attachment /*messageBodyPart = new MimeBodyPart(); String filename = "file.txt"; DataSource source = new FileDataSource(filename); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(filename); multipart.addBodyPart(messageBodyPart);*/ // Send the complete message parts message.setContent(multipart); // Send message Transport.send(message); System.out.println(to+" 메일 전송완료!"); } catch (MessagingException mex) { System.out.println(to+" 메일 전송에러!"); mex.printStackTrace(); } javax.mail.jar