JavaMail로 gmail보내기.
Java/Spring2009. 8. 28. 16:45
트랙백에 가보면 설정으로 되어있는데..
그냥 자바 코드로 했을 경우.
프로 스프링 2.5 참조
SimpleMailSender.java
JavaMailSimpleMailSender.java
SimpleMailTest
응...?
메일은 처음 보내 보는듯 -ㅅ-;;;
그냥 자바 코드로 했을 경우.
프로 스프링 2.5 참조
SimpleMailSender.java
public abstract class SimpleMailSender
{
protected abstract MailSender getMailSender();
public void sendMessage( String to, String text)
{
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo( to);
msg.setSubject( "Test Message");
msg.setFrom( "보내는 사람 주소");
msg.setText( text);
MailSender sender = getMailSender();
try {
sender.send( msg);
} catch (MailException e)
{
e.printStackTrace();
}
}
}
{
protected abstract MailSender getMailSender();
public void sendMessage( String to, String text)
{
SimpleMailMessage msg = new SimpleMailMessage();
msg.setTo( to);
msg.setSubject( "Test Message");
msg.setFrom( "보내는 사람 주소");
msg.setText( text);
MailSender sender = getMailSender();
try {
sender.send( msg);
} catch (MailException e)
{
e.printStackTrace();
}
}
}
JavaMailSimpleMailSender.java
public class JavaMailSimpleMailSender extends SimpleMailSender
{
protected MailSender getMailSender()
{
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost( "smtp.gmail.com");
sender.setPort( 465);
sender.setProtocol( "smtps");
sender.setUsername( "아이디");
sender.setPassword( "비밀번호");
sender.getJavaMailProperties().setProperty( "mail.smtps.auth", "true");
sender.getJavaMailProperties().setProperty( "mail.smtps.startls.enable", "true");
sender.getJavaMailProperties().setProperty( "mail.smtps.debug", "true");
return sender;
}
}
{
protected MailSender getMailSender()
{
JavaMailSenderImpl sender = new JavaMailSenderImpl();
sender.setHost( "smtp.gmail.com");
sender.setPort( 465);
sender.setProtocol( "smtps");
sender.setUsername( "아이디");
sender.setPassword( "비밀번호");
sender.getJavaMailProperties().setProperty( "mail.smtps.auth", "true");
sender.getJavaMailProperties().setProperty( "mail.smtps.startls.enable", "true");
sender.getJavaMailProperties().setProperty( "mail.smtps.debug", "true");
return sender;
}
}
SimpleMailTest
public class SimpleMailTest
{
private static final String TO = "받는사람 주소";
private static final String JAVAMAIL_TEXT = "HELLO WORLD! Email generated user JavaMail";
public static void main( String[] args)
{
SimpleMailSender sender = new JavaMailSimpleMailSender();
sender.sendMessage( SimpleMailTest.TO, SimpleMailTest.JAVAMAIL_TEXT);
}
}
{
private static final String TO = "받는사람 주소";
private static final String JAVAMAIL_TEXT = "HELLO WORLD! Email generated user JavaMail";
public static void main( String[] args)
{
SimpleMailSender sender = new JavaMailSimpleMailSender();
sender.sendMessage( SimpleMailTest.TO, SimpleMailTest.JAVAMAIL_TEXT);
}
}
응...?
메일은 처음 보내 보는듯 -ㅅ-;;;