JAVA2014. 2. 19. 16:07

인증없이 전송 샘플 : http://blog.daum.net/_blog/BlogTypeView.do?blogid=0fK9x&articleno=618

전송 샘플 : http://kodejava.org/how-do-i-send-an-email-with-attachment/

                http://blog.naver.com/PostView.nhn?blogId=hmleena&logNo=63968842

 

윈도우7 SMTP 설치 : http://blog.naver.com/PostView.nhn?blogId=livingsens&logNo=40186294416&redirect=Dlog&widgetTypeCall=true

 

 

import java.io.UnsupportedEncodingException;
import java.util.Properties;

import javax.mail.Authenticator;
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; 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SimpleMailTest {
    public static void main(String[] args) {    
        try {
            Properties props = new Properties();
            //props.put("mail.transport.protocol", "smtp");
            props.put("mail.smtp.host", "서버IP");
            props.put("mail.smtp.port", "서버PORT");      
            props.put("mail.smtp.auth", "false"); 
            //props.put("mail.smtp.starttls.enable","true");
            Authenticator authenticator = new Authenticator()
            {
            protected PasswordAuthentication getPasswordAuthentication()
            {
                return new PasswordAuthentication(null,null);
              }
            };
            //props.put("mail.smtp.auth", "true"); 
            //props.put("mail.smtp.starttls.enable", "false");   
            System.out.println( "2" );
            Session session = Session.getInstance(props) ;
            //Session session = Session.getDefaultInstance(props) ;
            System.out.println("2");
           
           
            InternetAddress fromAddress = new InternetAddress("jungws55@daum.net");
            InternetAddress toAddress   = new InternetAddress("jungws55@nate.com");
           

            MimeMessage message = new MimeMessage(session);
            message.setFrom(fromAddress);
            message.addRecipient(Message.RecipientType.TO, toAddress );
            message.setSubject("제목");
            message.setContent("내용"," text/html; charset=KSC5601");
            Transport.send(message);
            System.out.println("[{}] 메일 발송 성공 jungws55@nate.com");


         } catch (MessagingException e) {
             System.out.println(e);
         }


     }
}

 

'JAVA' 카테고리의 다른 글

[ERROR] java 오류 정리  (0) 2014.02.26
Socket으로 Mail 전송 샘플  (0) 2014.02.24
java.lang.reflect.Method 샘플  (0) 2013.12.05
Annotation Example  (0) 2013.12.05
static 키워드  (0) 2013.12.04
Posted by 선한열심