티스토리 뷰

gmail smtp 서버를 이용하면 메일서버 구축 없이 메일을 보낼 수 있다.


단 gmail계정을 만들어 gmail setting에 들어가 Forwarding and POP/IMAP탭에 


POP Download에 Enable POP for all mail (even mail that's already been downloaded)를 체크한 후

 

아웃룩에 지메일 계정을 추가해야 한다.  



<%@ page import="org.apache.commons.mail.HtmlEmail" %>



<%

String charSet = "euc-kr";

//String hostSMTP = "localhost";

String hostSMTP = "smtp.gmail.com";

//String hostSMTPid = "";

String hostSMTPid = "; //gmail  계정 ID

String hostSMTPpasswd = ""; //  gmail  계정  password

String fromEmail = "test@gmail.com";

String fromName = "test";

String subject = "test";


try {

HtmlEmail email = new HtmlEmail();  //html형식의 메일이 아닌 기본 메일일 경우에는 SimpleEmail email = new SimpleEmail()

email.setDebug(true);  

email.setCharset(charSet);

email.setSSL(true);

email.setHostName(hostSMTP);

email.setAuthentication(hostSMTPid, hostSMTPpasswd);

email.setTLS(true); 

email.addTo(mail, charSet);

email.setFrom(fromEmail, fromName, charSet);

email.setSubject(subject);

email.setHtmlMsg("<p align = 'center'>test.</p><br><div align='center'>테스트입니다..</div>");

email.send();

out.println("<script>alert('메일을 성공적으로 보냈습니다!'); history.go(-1);</script>");

} catch (Exception e) {

}


%>

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함