package eont.mail;
import org.apache.commons.mail.*;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import java.util.*;
import javax.mail.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.imageio.ImageIO.*;
import eont.mail.WebImage;
import eont.xml.eontConfig;
public class SendHtmlEmail {
static final Logger logger = Logger.getLogger("email");
public SendHtmlEmail() throws Exception{
try{
System.out.println("SendHtmlEmail initialize");
}catch (Exception e){
System.out.println(e.toString());
}
}
public static void Send(String mailsubject,
String mailto,
String mailto_name,
String mailfrom,
String mailsender,
String content,
String attach_name,
String save_path
) throws EmailException, MessagingException, UnsupportedEncodingException {
HtmlEmail htmlEmail = null;
Date currDate = new Date();
logger.debug("mailsubject : "+mailsubject);
logger.debug("mailfrom : "+mailfrom); // 보내는 사람
logger.debug("mailto : "+mailto); // 받는 사람
logger.debug("mailsender : "+mailsender);
htmlEmail = new HtmlEmail() ;
String SendingHtml = content;
try {
htmlEmail.setCharset("euc-kr");
htmlEmail.setHostName("0.0.0.0"); // 아이피
htmlEmail.setSmtpPort(25);
htmlEmail.setAuthenticator(new DefaultAuthenticator("아이디", "패스워드"));
htmlEmail.setDebug(true);
htmlEmail.setFrom(mailfrom, mailsender);
htmlEmail.addTo(mailto, mailto_name);
htmlEmail.setSubject(mailsubject);
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.socketFactory.port", "25");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.starttls.enable", "true");
Session sess = Session.getDefaultInstance(props, null);
/* 첨부파일 */
if(attach_name !=null
&& save_path !=null
&& !attach_name.equals("")
&& !save_path.equals("") )
{
eontConfig tc = new eontConfig();
save_path = tc.getConfigValue("AttachPathOutBound")+save_path;
EmailAttachment attachment = new EmailAttachment();
attachment.setPath(save_path); // 파일경로
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("");
attachment.setName(attach_name); // 실제 파일 이름
attachment.setName(new String(attach_name.getBytes("euc-kr"), "latin1")); // 한글 첨부파일 깨짐..
htmlEmail.attach(attachment);
}
htmlEmail.setHtmlMsg(SendingHtml);
htmlEmail.setSentDate(currDate);
htmlEmail.send();
}
catch (EmailException ee) {
//System.out.println(ee.toString());
}finally{
String fn = "receipt_email/receipt."+mailto+".html";
File f = new File(fn);
if(!f.delete())
logger.debug("fail delete file : receipt_email/receipt."+mailto+".html");
}
}
}
'프로그래밍 > java' 카테고리의 다른 글
이클립스 workspace 변경 파일 (0) | 2012.10.14 |
---|---|
이클립스 시작시 loading workbench eclipse 멈출때 (0) | 2012.10.14 |
[이클립스] 에디터 text 인코딩변경.. (0) | 2012.10.08 |
스프링 applicationContext.xml DB connect 접속 설정 예 (0) | 2012.10.08 |
jsp 파일 다운로드 (0) | 2012.09.18 |
jsp 페이지에서 보안서버 http 로 접근시 --> https 로 이동 (0) | 2012.09.12 |
org.apache.commons.fileupload 파일 업로드 (0) | 2012.08.16 |
eclipse.ini (0) | 2012.01.13 |
JRebel 연동하기 (0) | 2011.10.28 |
자바형변환 (0) | 2011.10.24 |
댓글