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(2)
 
¾Æ½Ã´Â ºÐÀº ¾Ë°ÚÁö¸¸ 2001³â¿¡ ¸ð¸ð »çÀÌÆ®¿¡ µ·(¹«·Á 900¿ø)¹Þ°í ¿Ã¶ó°£ ³»¿ëÀε¥ ¿äû¿¡ ÀÇÇÏ¿© ÀÚ¹ÙÆÐÅÏ»çÀÌÆ®¿¡ ´Ù½Ã °ø°³ÇÕ´Ï´Ù. ( 2003/04/25 ) 718
Written by ienvyou - ÃÖÁö¿õ
4 of 4
 


Transport Class

* Transport

ÀÚ.  Áö³­½Ã°£±îÁö ¸ÞÀϺ¸³»±â¿¡ ÁýÁßÇÏ¿© Çߴµ¥, ¿À´Ã µÞºÎºÐºÎÅÍ´Â ¸ÞÀÏÀ» ¹Þ¾Æ¿À´Â 

ºÎºÐ¿¡ ´ëÇÏ¿© ¼³¸íÀ» ÇÏ°Ô µÉ °ÍÀÌ´Ù.

¿ì¼± Àú¹ø ½Ã°£¿¡ ´Ù »ìÆ캸Áö ¸øÇß´ø ¸ÞÀϺ¸³»±âÀÇ TransportŬ·¡½º¿¡ ´ëÇÏ¿© »ìÆ캸µµ·Ï ÇÏÀÚ.


ÀÚ¹Ù¸ÞÀϺ¸³»±â·Î ¸ÞÀÏÀ» Àü¼ÛÇÒ¶§ °¡Àå ¸¶Áö¸·À¸·Î »ç¿ëµÇ´Â Ŭ·¡½º°¡ ¹Ù·Î TransportŬ·¡½ºÀÌ´Ù. 

ÀÌ Å¬·¡½º´Â ¸Þ½ÃÁö¸¦ º¸³»±â À§ÇØ Æ¯Á¤ÇÁ·ÎÅäÄÝ°ú ´ëÈ­Çϵµ·Ï ÇÑ´Ù.

(ÀϹÝÀûÀ¸·Î SMTP) ÀÌŬ·¡½º´Â Ãß»óŬ·¡½ºÀ̸ç, SessionŬ·¡½º¿Í ºñ½ÁÇÑ ÀÏÀ» ÇÑ´Ù. 

Default´Â static¸Þ¼Òµå´Â send()¸¦ ÀÌ¿ëÇÏ¿© ¸Þ½ÃÁö¸¦ º¸³»°Ô µÇ´Âµ¥ ¾Æ·¡¿Í °°´Ù

Transport.send(message);

À§ÀÇ ¹æ¹ý¸»°íµµ ÇÁ·ÎÅäÄÝÀ» À§ÇØ username, password¿¡ °üÇÑ Á¤º¸¸¦ ¼¼¼ÇÀ¸·ÎºÎÅÍ 

ÀνºÅϽº¸¦ ¾ò¾î¿Í ¸Þ½ÃÁö¸¦ º¸³»°í connectionÀ» close()½Ãų¼öµµ Àִµ¥ »ç¿ë¹ýÀº ¾Æ·¡¿Í °°´Ù.

message.saveChanges(); // implicit with send()
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();

ÇöÀç multiple¸Þ½ÃÁö¸¦ º¸³¾¶§´Â À§ÀÇ ¹æ¹ýÀÌ °¡Àå ÀÌ»óÀûÀÌ´Ù.

¿Ö³ÄÇϸé send() static¸Þ¼ÒµåÀÇ °æ¿ì °¢°¢ÀÇ ¸Þ½ÃÁö¸¦ º¸³¾¶§ ¼­¹öÃø¿¡ ¸Å¹ø connectionÀ» ¸Î°Ô²û 

¸¸µéÁö¸¸ À§ÀÇ °æ¿ìó·³ ÇÁ·Î±×·¥À» Â¥°Ô µÇ¸é ÇϳªÀÇ ConnectionÀ» ¿¬°á½ÃÄÑ ³õ°í, 

¸ÞÀÏÀÇ ¸Þ½ÃÁö¸¦ ¸ðµÎ º¸³¾¶§±îÁö ¿¬°áÀ» Áö¼Ó½ÃÅ°°Ô µÇ´Â ÀåÁ¡À» °¡Áö°í ÀÖ´Ù.

tip> ¸ÞÀÏÀü¼Û½Ã µµ½ºÃ¢¿¡ »óŸ¦ º¸±â À§ÇÑ´Ù¸é µð¹ö±×¿ëÀÎ session.setDebug(true)¸¦ ¾²±â ¹Ù¶õ´Ù.

¾Æ·¡´Â À§ÀÇ ¿¹Á¦Äڵ带 »ðÀÔ½ÃÄÑ ¸¸µç ¸ÞÀϺ¸³»±â ¿¹Á¦ÀÌ´Ù.



import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class MailExample {
  public static void main (String args[]) throws Exception {
    String host = "openitech.co.kr";
    String from = "ienvyou@openitech.co.kr";
    String to = "ienvyou@orgio.net";

    // Get system properties
    Properties props = System.getProperties();

    // Setup mail server
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.auth", "true");

    // Get session
    Session session = Session.getDefaultInstance(props, null);
	session.setDebug(true);

    // Define message
    MimeMessage message = new MimeMessage(session);

    // Set the from address
    message.setFrom(new InternetAddress(from));

    // Set the to address
    message.addRecipient(Message.RecipientType.TO, 
      new InternetAddress(to));

    // Set the subject
    message.setSubject("Hello JavaMail");

    // Set the content
    message.setText("Welcome to ÀÚ¹Ù¸ÞÀÏ");

    // Send message
	
    message.saveChanges(); // implicit with send()
    Transport transport = session.getTransport("smtp");
    transport.connect(host, "ienvyou", "0000");
    transport.sendMessage(message, message.getAllRecipients());
    transport.close();
	
  }
}

»¡°£ ±Û¾¾·Î ÄÚµùµÈ ºÎºÐÀÌ ½ÇÁúÀûÀÎ TransportŬ·¡½ºÀÇ ¼­¹öÀÎÁõºÎºÐÀ̸ç property°ª¿¡ authÇ÷¡±×°¡ true°ªÀ¸·Î ¼³Á¤µÇ¾î ÀÖ¾î¾ß Çϴ°ÍÀº ¿¹ÀüºÎÅÍ ´©´©È÷ °­Á¶Çß´ø ºÎºÐÀÌ´Ù.
 
1 2 3 4
References
 
Copyright ¨Ï 2003 www.javapattern.info & www.jlook.com, an jLOOK co.,LTD