import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;


public class SendUseAuthenticator{
	public static void main(String[] args){

	try{
		//设置属性值
		Properties props = System.getProperties();
		props.put("mail.smtp.host", "onecompany.com");
		props.put("mail.smtp.auth", "true");

		//Authenticator子类实例化
		Authenticator auth = new ConsoleAuthenticator(); 

		//获得Session
		Session session = Session.getDefaultInstance(props,auth);
		//session.setDebug(true);

		//写邮件消息
		MimeMessage msg = new MimeMessage(session);
		msg.setFrom(new InternetAddress("xiaozhang@onecompany.com"));
		Address toAddress=new InternetAddress("xiaoli@onecompany.com");
		msg.addRecipient(Message.RecipientType.TO,toAddress);
		msg.setSubject("JavaMail API TestMail ");
		msg.setSentDate(new Date());
		msg.setText("This is a test mail.");

		//设置Transport发送消息
		Transport.send(msg);

		System.out.println("\n邮件已发送!");
	}catch(Exception e){}

	}
}
