Site Search :
Standard Enterprise XML Methodology Pattern Setting Tunning Other
Article Contributors
GuestBook
Javapattern Maven
XSourceGen Dev
JetSpeed Test
JLook Image
jLook Family Site


Java WebMail System Implementation(4)
 
÷ºÎÆÄÀÏÀÇ ¸ÞÀϺ¸³»±â ¹× POP3¼­¹öÀÇ Æú´õ³»¿ëÀ» ÀÌ¿ëÇÏ¿© µ¥ÀÌÅ͸¦ °¡Á®¿Àµµ·Ï ÇÏ´Â »ùÇÃÀ» ¼³¸í°ú ÇÔ²² º¸µµ·Ï ÇÏÀÚ. ( 2003/05/13 ) 683
Written by ienvyou - ÃÖÁö¿õ
1 of 4
 

Prolog

¿äÁò ÀÚ¹Ù±â¼úÀ» ÀÌ¿ëÇÏ¿© ±²ÀåÈ÷ ¸¹Àº ÀϵéÀÌ ¹ú¾îÁö°í ÀÖ´Ù.

MobileÂÊÀ» ºñ·ÔÇÏ¿© ÀÏ¹Ý application ¹× ´ëÇü Enterpriseȯ°æ±îÁö ÀÚ¹Ù°¡ ¹ÌÄ¡´Â ¹üÀ§´Â Á¤¸» ±¤´ëÇÏ´Ù.

¿©±â¼­ ½ÃÀ۵Ǵ ¿¬Àç´Â ÇöÀç J2EE(Java 2 Enterprise Edition)ÀÇ JavaMailÀ» ´Ù·ê °ÍÀÌ´Ù.

À̹ø ¿¬Àç¿¡¼­ ÀÚ¹ÙÀÇ ¿ª»ç°¡ ÀÌ·¸´Ù Àú·¸´Ù ÇÒ¼ö ÀÖ´Â »óȲÀº ¾Æ´Ñ°Í °°´Ù.

À̱ÛÀ» Àд »ç¶÷Àº OOP(Object Oriented Programming)ÀÇ °³³äÀ» Á¤È®È÷ ¾Ë°í ÀÖ¾î¾ß ÇÒ°ÍÀÌ´Ù.

J2EEÂÊ È¯°æÀ̶ó¸é ¿ì¼± ±âº»ÀûÀÎ Áö½ÄÀ» °®Ãß¾î¾ß ÇÏÁö¸¸ º» ³»¿ëÀº ¼Ò½ºÄڵ带 º¹»çÇÏ¿©

¿©·¯ºÐµéÀÇ ÆíÁý±â¿¡ ºÙ¿©³Ö°í ÄÄÆÄÀÏÇÑÈÄ ½ÇÇà½ÃÄѵµ µ¹¾Æ°¥¼ö ÀÖ°Ô²û ¸¸µé¾ú´Ù.

ÀåȲÇÑ ¼³¸íÀº ÇÏÁö ¾Ê°Ú´Ù. ÀÌÁ¦ interfaceÀÇ Áø¼ö¸¦ ¸Àº¸µµ·Ï ÇÏÀÚ.


¢ºContent(1ºÎ)
  1. Mail Attachment

  2. ÷ºÎÆÄÀÏ ¸ÞÀϺ¸³»±â ¼Ò½ºº¸³»±â

  3. ÷ºÎµÈ ³»¿ë°¡Á®¿À±â

  4. HTMLÀÌ Æ÷ÇÔµÈ ¸ÞÀÏ ¹× À̹ÌÁö ÷ºÎÇÏ¿© º¸³»±â

####################################################### # Java Mail API 1.2¸¦ ÀÌ¿ëÇÑ À¥¸ÞÀÏ ½Ã½ºÅÛÀÇ ±¸Çö. # ####################################################### ¢ºÆÄÀÏ Ã·ºÎÇÏ¿© º¸³»±â(Çѱ۱úÁü ó¸®) ÆÄÀÏ÷ºÎ´Â ÀÏ¹Ý ÅؽºÆ®ÆÄÀÏ, À̹ÌÁöµîÀ» ¸ÞÀÏÀÇ ¸Þ½ÃÁö¿Í °°ÀÌ Á¶ÇÕÇÏ¿© º¸³»´Â ¹æ¹ýÀÌ´Ù. ÀϹÝÀûÀÎ Eudora³ª pine°°Àº ÇÁ·Î±×·¥Ã³·³ JavaMail API¶ÇÇÑ ¸Þ½ÃÁö¿¡ ÆÄÀÏÀ» ÷ºÎÇÏ¿© º¸³¾¼ö ÀÖ´Â ±â´ÉÀ» Á¦°øÇÑ´Ù. 1. ÆÄÀÏ º¸³»±â ÆÄÀϺ¸³»´Â °Íµµ ¸Þ½ÃÁö¸¦ º¸³»´Â °Í°ú ¸¶Âù°¡Áö·Î PartÀÎÅÍÆäÀ̽ºµéÀ» »ç¿ëÇÑ´Ù. °¢°¢ÀÇ Ã·ºÎ¸¦ Á¶ÇÕÇϱâ À§ÇØ¿© DataHandlerÀÎÅÍÆäÀ̽º¸¦ »ç¿ëÇÏ¿© ´Ù¸¥ partºÎºÐ¿¡ ÷°¡½ÃÄÑ¾ß ÇÑ´Ù. ¸¸¾à ¸ÞÀÏ¿¡ ÆÄÀÏÀ» ÷ºÎÇÏ°íÀÚ ÇÑ´Ù¸é FileDataSource Ŭ·¡½º¸¦ »ç¿ëÇÏ¿© ¸ÞÀÏ¿¡ ÷ºÎÇÏ¿©¾ß ÇÒ°ÍÀÌ´Ù. ¶ÇÇÑ URLÀ» »ç¿ëÇÏ°íÀÚ ÇÑ´Ù¸é URLDataSource¸¦ »ç¿ëÇϵµ·Ï ÇÑ´Ù. ¿ì¼± BodyPart°´Ã¼¸¦ »ý¼ºÇÑ ÈÄ¿¡ DataSource°´Ã¼¸¦ »ý¼ºÇϵµ·Ï ÇÑ´Ù. DataSource¸¦ °´Ã¼·Î °¡Áö°Ô µÇ¾ú´Ù¸é, ±× DataSource °´Ã¼¸¦ DataHandlerÀÇ »ý¼ºÀÚ¿¡ argument°ªÀ¸·Î °ªÀ» ³Ñ±â°Ô ÇÏ¿©¾ß ÇÏ°í, BodyPart°´Ã¼ÀÇ setDataHandler()¸Þ¼Òµå¸¦ »ç¿ëÇÏ¿© DataHandler¸¦ ³Ñ±âµµ·Ï ÇÑ´Ù. ¸¶Áö¸·À¸·Î ÇÒÀÏÀº BodyPartÀÇ setFileName()¸Þ¼Òµå¸¦ ÀÌ¿ëÇؼ­ ¿ø·¡ º¸³»°íÀÚÇÏ´Â ÆÄÀÏÀÇ À̸§À» ¸í½ÃÇϵµ·Ï ¼¼ÆýÃÅ°¸é µÈ´Ù. ¸ðµç ¼ø¼­ÄÚµåÀÇ ³»¿ëÀº ¾Æ·¡¿Í °°´Ù. // º¸³¾ ¸Þ½ÃÁöÀÇ ¼±¾ð. Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("Hello JavaMail Attachment"); // ù¹ø° Message BodyPartÀÇ »ý¼º BodyPart messageBodyPart = new MimeBodyPart(); // º¸³¾ ³»¿ëÀÇ ¼¼Æà messageBodyPart.setText("Pardon Ideas"); // ù¹ø° ¸Þ½ÃÁö ³»¿ëÀÇ ºÎºÐÀ» multiPart¿¡ ÷°¡ÇÑ´Ù. Multipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); // µÎ¹ø° ºÎºÐÀÇ °áÇÕ(ÆÄÀÏ Ã·ºÎÄÚµå) messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(filename); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(filename); multipart.addBodyPart(messageBodyPart); // °áÇÕµÈ µÎ°³ÀÇ part¸¦ ¸Þ½ÃÁöÀÇ content¿¡ ¼¼ÆÃÇϵµ·Ï ÇÑ´Ù. message.setContent(multipart); //¸Þ½ÃÁö º¸³»±â Transport.send(message); ¸¸¾à ÆÄÀϺ¸³»±â ¿¹Á¦¸¦ ¼­ºí¸´ ÇÁ·Î±×·¥À¸·Î ÄÚµùÇÏ°Ô µÈ´Ù¸é ÆÄÀÏÀ» ¾÷·ÎµåÇÒ¼ö ÀÖ´Â htmlű×ÀÎ multipart/form-data¸¦ »ç¿ëÇÒ¼ö ÀÖ´Ù. <FORM ENCTYPE="multipart/form-data" method=post action="/myservlet"> <INPUT TYPE="file" NAME="thefile"> <INPUT TYPE="submit" VALUE="Upload"> </FORM> NOTE>¸Þ½ÃÁöÀÇ Å©±â´Â JavaMail API°¡ ¾Æ´Ñ SMTP¼­¹öÀÇ ÇÑ°è°ªÀÌ ±âÁØÀÌ´Ù. ¾Æ·¡ÀÇ ÇÁ·Î±×·¥Àº ¼­¹ö¿¡ ÀÚ½ÅÀÇ ¾ÆÀ̵ð¿Í Æнº¿öµå¸¦ ÀÎÁõÇÏ´Â ºÎºÐ¿¡¼­ ¶Ç ´Ù¸¥ ¹æ¹ýÀ» º¸¿©ÁØ´Ù. ConnectionListener¶ó´Â °Í°ú TransportListener¶ó´Â ÀÎÅÍÆäÀ̽º¸¦ »ó¼Ó¹Þ¾Æ »ç¿ëÇÏ´Â °ÍÀ» º¸¿©ÁÖ°í ÀÖ´Ù. ¿©·¯ºÐµé¿¡°Ô optionalÇÏ°Ô º¸¿©ÁÖ±â À§ÇØ ¸¸µç ÄÚµåÀÌ´Ï ÂüÁ¶Çϱ⠹ٶó¸ç Áß°£¿¡ ÇѱÛÆÄÀÏ÷ºÎ½Ã ÆÄÀÏÀ̸§ÀÌ ±úÁö´Â ¹®Á¦¸¦ ÇØ°áÇÑ Äڵ带 Áý¾î³Ö¾ú´Ù.
 
1 2 3 4
References
 
¾ÆƼŬ¼Ò½º : javaMail2.zip
Copyright ¨Ï 2003 www.javapattern.info & www.jlook.com, an jLOOK co.,LTD