1. ¸ÞÀÏ ¹ß¼ÛÆû(sendmail.html)

<html>

 <head><title>Sending a Custom Email - HTML Form</title></head>

 <body>

  <p align="center"><b>A custom email utility.</b></p>

  <form name="form" action="sendmail.jsp" method="post">

   <table align="center">

<tr><td>From</td><td><input name="from" size="50" value=""></td></tr>

     <tr><td>To</td><td><input name="to" size="50"  value="chchu@ihelpers.co.kr"></td></tr>

     <tr><td>Subject</td><td>

      <input name="subject" size="50" value="[JavaMail Example - http://www.ihelpers.co.kr]">

     </td></tr>

     <tr><td colspan="2">

      <textarea name="text" cols="50" rows="20">Hello from JavaMail!</textarea>

     </td></tr>

     <tr><td colspan="2" align="center"><input type="submit" value="Send Email"></td></tr>

   </table>

  </form>

 </body>

</html>

2. ¸ÞÀÏ ¹ß¼Û JSP ÆäÀÌÁö(sendmail.jsp)

<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>

<%

             String subject = new String(request.getParameter("subject").getBytes("8859_1"),"KSC5601");

             String text = new String(request.getParameter("text").getBytes("8859_1"),"KSC5601");

             Properties props = new Properties();

             String host = "mail.your.server"; // SMTP ¼­¹ö ¼³Á¤

             props.put("mail.smtp.host", host);

             Session s = Session.getInstance(props,null);

             MimeMessage message = new MimeMessage(s);

             String fromAddress = request.getParameter("from");        //º¸³»´ÂÀÌ

             InternetAddress from = new InternetAddress(fromAddress);

             message.setFrom(from); // º¸³»´ÂÀÌ ¼³Á¤

             String toAddress = request.getParameter("to");

             InternetAddress to = new InternetAddress(toAddress); // ¹Þ´ÂÀÌ ¼³Á¤

             message.addRecipient(Message.RecipientType.TO, to);  

             message.setSubject(subject); // Á¦¸ñ

             message.setContent(text, "text/html; charset=EUC-KR"); // content Type ¼³Á¤

             message.setText(text); // º»¹®

             Transport.send(message); // ¸ÞÀÏ ¹ß¼Û

%>

<html>

<p align="center">The Message has been sent.<br>Check your inbox.</p>

<p align="center"><a href="sendmail.html">Click here to send another!</a></p>

</html>

 

À§ÀÇ ºÎºÐ¿¡¼­ ƯÈ÷ ´«¿©°Ü º¸½Ç ºÎºÐÀº SMTP ¼­¹ö·Î »ç¿ëµÉ ¼­¹ö¸¦ ÁöÁ¤ÇÏ´Â ºÎºÐ

(String host = "mail.your.server") °ú ¸Þ½ÃÁöÀÇ ÇѱÛÈ­ ó¸® ºÎºÐÀÔ´Ï´Ù.

±×¸®°í ¸ÞÀÏÀÇ content ŸÀÔÀ» ¼³Á¤ÇÏ´Â ºÎºÐÀÔ´Ï´Ù. (message.setContent(text, "text/html; charset=EUC-KR");)

´Ü¼øÈ÷ ÅؽºÆ®·Î¸¸ ¹ß¼ÛÇÒ°æ¿ì¿¡´Â text/html ´ë½Å¿¡ text/plainÀ¸·Î ¹Ù²Ù½Ã¸é µË´Ï´Ù.

 

±×¹ÛÀÇ ºÎºÐÀº ÀÚ¹Ù¸ÞÀÏ ¼³Ä¡½Ã ÇÔ²² Á¦°øµÇ´Â ¹®¼­¸¦ ÂüÁ¶ÇϽñ⠹ٶø´Ï´Ù.

 

- www.okjsp.pe.kr

- java.sun.com

- www.hotscripts.com