SSL로 메일 전송을 해보자.
프로토콜은 : smtps
--------------------------------------------------------------------------------
성공이면 아래와 같은 응답이 온다.
--------------------------------------------------------------------------------
Response: 250 2.0.0 OK 1193154318 m27sm9166401pof
--------------------------------------------------------------------------------
인증 에러가 나면 아래와 같은 응답이 온다.
--------------------------------------------------------------------------------
Response: 530 5.5.1 Authentication Required n22sm9130327pof
--------------------------------------------------------------------------------
public void send() throws Exception {
Session session = getSession();
SMTPTransport tr = null;
try {
tr = (SMTPTransport)session.getTransport(protocol);
tr.connect(host, port, userid, password);
Message msg = makeMailMessage(session);
msg.saveChanges();
tr.sendMessage(msg, msg.getAllRecipients());
} finally {
if (tr != null) {
System.out.println("Response: " + tr.getLastServerResponse()); // 응답을 찍어보자.
tr.close();
}
}
}
--------------------------------------------------------------------------------
private Message makeMailMessage(Session session) throws Exception {
SMTPMessage msg = new SMTPMessage(session);
// 알아서 만들고~
return msg;
}
--------------------------------------------------------------------------------
private Session getSession() {
Properties props = new Properties();
props.setProperty("mail.smtp.host", this.host);
props.setProperty("mail.smtp.port", String.valueOf(this.port));
props.setProperty("mail.smtps.auth", "true");
props.setProperty("mail.smtp.connectiontimeout", "10000");
props.setProperty("mail.smtp.timeout", "10000");
props.put("mail.smtp.debug ","true");
return Session.getInstance(props);
}
--------------------------------------------------------------------------------
javamail api: http://java.sun.com/products/javamail/javadocs/index.html
인증에 관한 문서 http://www.ietf.org/rfc/rfc2554.txt
프로토콜은 : smtps
--------------------------------------------------------------------------------
성공이면 아래와 같은 응답이 온다.
--------------------------------------------------------------------------------
Response: 250 2.0.0 OK 1193154318 m27sm9166401pof
--------------------------------------------------------------------------------
인증 에러가 나면 아래와 같은 응답이 온다.
--------------------------------------------------------------------------------
Response: 530 5.5.1 Authentication Required n22sm9130327pof
--------------------------------------------------------------------------------
public void send() throws Exception {
Session session = getSession();
SMTPTransport tr = null;
try {
tr = (SMTPTransport)session.getTransport(protocol);
tr.connect(host, port, userid, password);
Message msg = makeMailMessage(session);
msg.saveChanges();
tr.sendMessage(msg, msg.getAllRecipients());
} finally {
if (tr != null) {
System.out.println("Response: " + tr.getLastServerResponse()); // 응답을 찍어보자.
tr.close();
}
}
}
--------------------------------------------------------------------------------
private Message makeMailMessage(Session session) throws Exception {
SMTPMessage msg = new SMTPMessage(session);
// 알아서 만들고~
return msg;
}
--------------------------------------------------------------------------------
private Session getSession() {
Properties props = new Properties();
props.setProperty("mail.smtp.host", this.host);
props.setProperty("mail.smtp.port", String.valueOf(this.port));
props.setProperty("mail.smtps.auth", "true");
props.setProperty("mail.smtp.connectiontimeout", "10000");
props.setProperty("mail.smtp.timeout", "10000");
props.put("mail.smtp.debug ","true");
return Session.getInstance(props);
}
--------------------------------------------------------------------------------
javamail api: http://java.sun.com/products/javamail/javadocs/index.html
인증에 관한 문서 http://www.ietf.org/rfc/rfc2554.txt


덧글