[Java] 초간단 Mail 보내기 클래스.

Programming 2013.01.07 19:47

초간단 Mail 보내기 클래스 만들기!


pom.xml

<dependency>

<groupId>javax.mail</groupId>

<artifactId>mail</artifactId>

<version>1.4.3</version>

</dependency>


MailSender.java

import javax.mail.MessagingException;

import javax.mail.internet.MimeMessage;


import org.springframework.mail.javamail.JavaMailSenderImpl;

import org.springframework.mail.javamail.MimeMessageHelper;


import com.devsisters.game.oven2.domain.IapErrorReport;


public class MailSender {

    private static final String HOST = "smtp.host.com";

    private static final String EMAIL_ADDR = "sender@host.com";

    private static final String EMAIL_PWD = "password";


    private static JavaMailSenderImpl sender = new JavaMailSenderImpl();


    public static void SendIapErrorMail(String title, String msg, String toMail) {


sender.setHost(MAIL_HOST);

sender.setUsername(EMAIL_ADDR);

sender.setPassword(EMAIL_PWD);


MimeMessage message = sender.createMimeMessage();

MimeMessageHelper helper = new MimeMessageHelper(message);

try {

    helper.setTo(toMail);

    helper.setSubject(title);

    helper.setText(msg);

    helper.setFrom(EMAIL_ADDR);

    sender.send(message);

} catch (MessagingException e) {

    e.printStackTrace();

}

    }

}


저작자 표시 비영리 변경 금지
신고


티스토리 툴바