<%@page contentType = "text/html; charset=euc-kr" %>
<%@ page import="java.util.*,java.io.*,javax.mail.*,javax.mail.internet.*,javax.activation.*" %>
<%
// javamail lib ÀÌ ÇÊ¿äÇÕ´Ï´Ù.
class MyAuthentication extends Authenticator {
PasswordAuthentication pa;
public MyAuthentication(){
pa = new PasswordAuthentication("ID", "PASSWD"); //ex) ID:iisweb@iisweb.co.kr PASSWD:1234
}
public PasswordAuthentication getPasswordAuthentication() {
return pa;
}
}
String subject = "Test"; //subject
String msgText = "Test test\ntest\ntest"; //message
String host = "mail-001.iisweb.co.kr"; //smtp mail server
String from = "from@from.com"; //sender email address
String to = "to@to.com"; //receiver email address
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth","true");
Authenticator auth = new MyAuthentication();
Session sess = Session.getInstance(props, auth);
try {
Message msg = new MimeMessage(sess);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(msgText);
Transport.send(msg);
out.println("^_^");
} catch (MessagingException mex) {
out.println(mex.getMessage()+"<br>");
out.println("-_-;;");
}
%>