달력

52024  이전 다음

  • 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

 public boolean sendMail(String filePath,String host, String receiver, String sender, String subject, String contents, InquireFile[] files){
  
  boolean flag = false;
  
  Properties prop = new Properties();
  
  prop.put("mail.smtp.host" , host);
  
  Session mailSession = Session.getDefaultInstance(prop, null);
  
  try{
   
   InternetAddress from = new InternetAddress(sender);
   
   Message msg = new MimeMessage(mailSession);
   
   msg.setFrom(from);
   
   msg.setRecipient(Message.RecipientType.TO, new InternetAddress(receiver));
   
   msg.setSubject(subject);
   
   Multipart multi = new MimeMultipart();      
   
   MimeBodyPart mbp = new MimeBodyPart();
   
   mbp.setContent(contents, "text/html; charset=ms949");
   
   multi.addBodyPart(mbp);
   
   if(files != null){
    
    for(int i = 0; i < files.length; i++){
     
     if(files[i] == null ) continue;
     
     DataSource fds = new FileDataSource(filePath + "/" + files[i].getFileName() );
     
     MimeBodyPart m = new MimeBodyPart();
     
     m.setDataHandler(new DataHandler(fds));
  
     m.setFileName(  toEng(fds.getName() ) );
     
     multi.addBodyPart(m);
     
    }
   }
   
   msg.setContent(multi);
   
   msg.setSentDate(new Date());
   
   Transport.send(msg);
   
   
   flag = true;
   
   
  }catch(Exception e){
   
   Logger logger = Logger.getLogger(this.getClass());   
   
   logger.error(this.getClass().getName() + " : " + e);
   
  }
  
  return flag;
  
 }

 

 public static String toEng(String origin) throws Exception{
  
  
  return new String(origin.getBytes(), "ISO-8859-1");
 }

 

==================================================================================

 

재미 있는건  한글 변환 부분 에서 new String(한글.getBytes("KSC5601"), "ISO-8859-1") 처럼 안해두 된다는것임...

 

다운로드시 한글 변환도 위와 같이 하면 URLEncoding 을 안해도 됨 ㅡㅡ 

 

daum.net , naver.com, hotmail.com, outlook express 에서 테스트 함

 

테스트 환경 : Win xp , tomcat 4.1.30 , Apache 2.0.49 , j2sdk 1.4.2_05

 

사용 디비 :  MySQL, Informix , Oracle

Posted by tornado
|