본문바로가기
현재위치 > JSP > 메일

메일

필수 jar

  • mail.jar

다운로드

Source

.
.
.
// 정보를 담기 위한 객체
Properties props = new Properties();

// SMTP 서버의 계정 설정
props.put( "mail.smtp.host" , "mw-002.cafe24.com" );
props.put( "mail.smtp.auth" , "true" );

// 메일 인증 계정 및 비번
Authenticator myauth=new MemberSendMail();

// 메일서버에서 계정 인증 검사
Session s = Session.getInstance( props, myauth );

try {
	Message msg = new MimeMessage( s );

	// 보내는 사람 메일 주소
	msg.setFrom( new InternetAddress( "kleap@rips.co.kr" ) );

	// 받는 사람 메일 주소
	InternetAddress[] address = { new InternetAddress( "(받는사람 이메일 주소)" ) };

	// 받는 사람 ( 다수 )
	// InternetAddress[] address = { new InternetAddress( to ) , new InternetAddress( to2 ) , new InternetAddress( to3 ) };

	msg.setRecipients( Message.RecipientType.TO , address );

	// 메일 제목
	msg.setSubject( "(제목)" );

	// 메일 내용
	msg.setContent(
		"(보내고자 하는 내용)" , "text/html;charset=UTF-8" );

	// 메일 전송
	Transport.send( msg );

	// 완료 페이지로 이동
	pageContext.forward( "./result.jsp" );
} catch( Exception e ) { out.println( e ); }
.
.
.

Class

.
.
.
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;

public class MemberSendMail extends Authenticator {

	protected PasswordAuthentication getPasswordAuthentication() {
		return new PasswordAuthentication( "(이메일계정)" , "(비밀번호)" );
	}
}