[java] javax.mail 패키지를 이용해서 메일 보내기

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
String emailAddressFrom = …;
String emailAddressTo = …;
String subject = …;
String message = …;

Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);

Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(emailAddressFrom));
msg.addRecipient(Message.RecipientType.TO,
                          new InternetAddress(emailAddressTo));
msg.setSubject(subject);
msg.setText(message);
Transport.send(msg);

Comments

comments