public void sendMail(MailEty mailEty){
  
  try{
   
//   create some properties and get the default Session
   Properties props = new Properties();
   props.put("mail.smtp.host", mailEty.getSmtphost());

   Session sess = Session.getDefaultInstance(props, null);
   
//   create a message
   Message msg = new MimeMessage(sess);
   
   msg.setFrom(new InternetAddress(mailEty.getFrom()));
   InternetAddress[] address = {new InternetAddress(mailEty.getTo())};
   msg.setRecipients(Message.RecipientType.TO, address);
   msg.setSubject(mailEty.getMailSubject());
   msg.setSentDate(new Date());
   
   
    //
            // This HTML mail have to 2 part, the BODY and the embedded image
            //
            MimeMultipart multipart = new MimeMultipart("related");

            // first part  (the html)
            BodyPart messageBodyPart = new MimeBodyPart();
              
   String htmlText = "<HTML>" +
    "<HEAD><TITLE></TITLE></HEAD>" +
    "<BODY>" +
     "<table><tr><td>"+
     "<br>"+
     "Dear "+mailEty.getName()+",<br>"+
     " <br>"+
     " </td>"+
     "</tr>"+
     "<tr>"+
     " <td width=100%><img src=\"cid:starhublogoimg\"></img></td>"+
     "</tr>"+
     "</table>"+
     "</BODY>" +
    "</HTML>";
   
    messageBodyPart.setContent(htmlText, "text/html");
   
    //add it
          multipart.addBodyPart(messageBodyPart);

         
          // second part (the image)
             messageBodyPart = new MimeBodyPart();
            
             String filePath = mailEty.getPath()+"/images/starhub_mail_logo.gif";
            
             DataSource fds = new FileDataSource(filePath);
             messageBodyPart.setDataHandler(new DataHandler(fds));
             messageBodyPart.setHeader("Content-ID","<starhublogoimg>");

             // add it
             multipart.addBodyPart(messageBodyPart);
   
   //msg.setContent(htmlText,"text/html; charset=euc-kr"); // HTML 형식
         msg.setContent(multipart); // HTML 형식
//   msg.setText(msgText); // TEXT 형식
   Transport.send(msg);
   logger.info(mailEty.getTo()+" mail send!");
            
   
  }catch(MessagingException mex){
   logger.error(mex.getMessage()+"<br>");
   logger.error(mailEty.getSmtphost()+" connected error! \n mail send fail!");
  }
  
  
 }

Posted by 복태아빠
,