import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class SimpleSendMail {
public SimpleSendMail() {
}
public static void main(String[] args) {
String host = "smtp.163.com";
String to = "mchotdog_011@126.com";
String from = "mchotdog_011@163.com";
String subject = "发送测试";
String messageText = "http://ltchina.net";
boolean sessionDebug = false;
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(sessionDebug);
try {
MimeMessage meg = new MimeMessage(session);
meg.setFrom(new InternetAddress(from));
InternetAddress[] address = { new InternetAddress(to) };
meg.setRecipients(Message.RecipientType.TO, address);
meg.setSubject(subject);
meg.setText(messageText);
meg.setSentDate(new Date());
meg.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect("smtp.163.com", "mchotdog_011", "mchotdog");
transport.sendMessage(meg, meg.getAllRecipients());
System.out.println("send over");
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
}