시소당
// package mail;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SendEmail
{
public static void main(String[] args)
{
String to = "kkk@nate.com"; //수신인 주소
String from = "xxx@zzz.com"; //발신인 주소
Properties props = new Properties();
Session session = Session.getInstance(props);
try
{
MimeMessage msg = new MimeMessage(session); //메세지 내용 담당 클래스인 MimeMessage 객체 생성
msg.setFrom(new InternetAddress(from)); //발신자 의 IP
InternetAddress address = new InternetAddress(to);//수신자의 IP (수신자가 다수일 경우 배열로 선언)
msg.setRecipient(Message.RecipientType.TO, address);
msg.setSubject("메일연습 ");
msg.setSentDate(new Date()); //날짜 구함
msg.setText("안녕하세요. 메일발송테스트입니다..");
Transport.send(msg); //메일발송
}
catch(MessagingException mex)
{
mex.printStackTrace();
}
catch (Exception e) {}
}
}
※ 메일을 보내는데 사용되는 서버가 localhost일 경우 설치된 James 서버를 실행 시키고 실행할것