源码如下:
package mail;import java.util.Date;
import java.util.Properties;import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class MailSend {
private String host;
private String to;
private String from;
private Message msg;
private Transport tran ;
public MailSend(String host ,String to,String from){
this.host=host;
this.from=from;
this.to=to;
Properties proper = System.getProperties();
proper.put("mail.host", host);
proper.put("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(proper,null);
mailSession.setDebug(true);
try{
msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress(from));
InternetAddress[] addressTo={new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, addressTo);
tran = mailSession.getTransport("smtp"); 
}catch(Exception e){
e.printStackTrace();
}
}
public void send(String subject,String messageTest){
try{
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageTest);
tran.connect("smtp.sina.com",25,"bewich@sina","chenbin");
    tran.send(msg);
}catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] arg){
MailSend send = new MailSend("smtp.sina.com","[email protected]","[email protected]");
send.send("haha", "60.191.164.236, port: 25.......");
}
}然后错误日志信息的提示如下:
DEBUG SMTP: trying to connect to host "smtp.sina.com", port 25220 mail5-202.sinamail.sina.com.cn ESMTP
DEBUG SMTP: connected to host "smtp.sina.com", port: 25EHLO PC-200810091135
250-mail5-202.sinamail.sina.com.cn
250-8BITMIME
250-SIZE 52428800
250-AUTH PLAIN LOGIN
250 AUTH=PLAIN LOGIN
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "AUTH=PLAIN", arg "LOGIN"
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
530 Authentication required
QUIT