Properties props = System.getProperties();
props.put("mail.smtp.host","smtp.163.com");
props.put("mail.smtp.auth","true");
MyAuthenticator auth = new MyAuthenticator();
Session mailsession = Session.getDefaultInstance(props,auth);
MimeMessage mail = new MimeMessage(mailsession);
mail.setFrom(new InternetAddress("[email protected]"));
mail.setRecipient(Message.RecipientType.CC,new InternetAddress("[email protected]"));
mail.setSubject("This is for test");
mail.setText("Hello world!");
Transport.send(mail);/////////////////////////
/////////////////////////
class MyAuthenticator extends Authenticator{
public MyAuthenticator(){
super();
}
public PasswordAuthentication getPasswordAuthentication(){
return new javax.mail.PasswordAuthentication("xxx","mypassword");
}}