package com.techown.lib.mail;import java.io.UnsupportedEncodingException;
import java.util.Properties;import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;public class Mail {
// 邮件服务属性
private Properties _properties = new Properties();
public void setProperties(Properties properties) { this._properties = properties; }
private Properties getProperties() { return this._properties; }
// 获取发件人
protected String getHost() {
return this.getProperties().getProperty("mail.smtp.host"); 
}
protected String getUser() { 
return this.getProperties().getProperty("mail.smtp.user"); 
}
protected String getPassword() {
return this.getProperties().getProperty("mail.smtp.password");
}
// 邮件服务会话
private Session _session = null;
protected Session getSession() { return this._session; }
// 构造函数
public Mail(String host, String port, String auth, final String user, final String password) {
// 设置SMTP地址
this.getProperties().put("mail.smtp.host", host); 
// 设置SMTP端口
this.getProperties().put("mail.smtp.port", "" + port); 
// 设置是否要认证
this.getProperties().put("mail.smtp.auth", "" + auth);
// 设置用户
this.getProperties().put("mail.smtp.user", user); 
// 设置密码
this.getProperties().put("mail.smtp.password", "" + password); 
// 设置TTL
this.getProperties().put("mail.smtp.starttls.enable", "true"); 
// 设置SocketFactory端口
this.getProperties().put("mail.smtp.socketFactory.port", "" + port); 
// 设置SSL套接字
this.getProperties().put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
this.getProperties().put("mail.smtp.socketFactory.fallback", "false");
// 获取会话实例
this._session = Session.getInstance(
this._properties, 
new Authenticator(){
protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication(user, password);
}
}
);
// 设置调试
this._session.setDebug(true);
}
//
private MimeMessage _message = null;
// 缺省邮件设置
public void setDefault(String from, String[] to, String[] cc, String[] bcc, String subject) throws MessagingException {
// 新建邮件
this._message = new MimeMessage(this._session);
// 设置发件人
try {
this._message.setFrom(new InternetAddress(this.getUser(),MimeUtility.encodeText(from,"utf-8","b")));
} catch (UnsupportedEncodingException e) {
this._message.setFrom();
}
// 设置收件人
if(to != null) {
InternetAddress[] address = new InternetAddress[to.length];
for(int i = 0; i < address.length; i ++) address[i] = new InternetAddress(to[i]);
this._message.setRecipients(Message.RecipientType.TO, address);
}
// 设置收件人
if(cc != null) {
InternetAddress[] address = new InternetAddress[cc.length];
for(int i = 0; i < address.length; i ++) address[i] = new InternetAddress(cc[i]);
this._message.setRecipients(Message.RecipientType.CC, address);
}
// 设置收件人
if(bcc != null) {
InternetAddress[] address = new InternetAddress[bcc.length];
for(int i = 0; i < address.length; i ++) address[i] = new InternetAddress(bcc[i]);
this._message.setRecipients(Message.RecipientType.BCC, address);
}
// 设置主题
this._message.setSubject(subject);
}
// 添加文本内容
public void setPart(String content, String type) throws MessagingException {
// 创建内容
MimeBodyPart body = new MimeBodyPart();
body.setContent(content, type + ";charset=UTF-8");
// 添加
Multipart part = new MimeMultipart();
part.addBodyPart(body);
// 设置内容
this._message.setContent(part);
}
// 
public void setHtmlWithImagePart(String text, String filename) throws MessagingException {
// 设置文本
    MimeBodyPart html = new MimeBodyPart();  
    html.setContent(text,"text/html;charset=UTF-8");  
    // 设置图像
    FileDataSource file = new FileDataSource(filename);  
    MimeBodyPart image = new MimeBodyPart();  
    image.setFileName(file.getName());  
    image.setDataHandler(new DataHandler(file));  
    image.setHeader("Content-ID", "<" + file.getName() + ">");  
    // 添加
    MimeMultipart part = new MimeMultipart("related");  
    part.addBodyPart(html);  
    part.addBodyPart(image);
    // 设置内容
    this._message.setContent(part);
} // 发送邮件
public void send() throws MessagingException { Transport.send(this._message); }
// 发送邮件
public void send(String from, String[] to, String[] cc, String[] bcc, String subject, String content, String type) throws MessagingException {
this.setDefault(from, to, cc, bcc, subject);
this.setPart(content, type);
this.send();
}
}下面是调用该方法实现发送邮件功能package Test;import javax.mail.MessagingException;import com.techown.lib.mail.Mail;public class TestSendMail { private boolean sendEmail(String[] emails){
boolean result=false;
Mail mail=new Mail("smtp.qq.com", "25", "true","570366997", "caoxinyu236200");
try {
mail.send("[email protected]", emails, null, null, "Test", "<b>test111</b>", "text/html");
result=true;
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;

}
public static void main(String []aaa){
TestSendMail t=new TestSendMail();
String []emails={"[email protected]"};
boolean result=t.sendEmail(emails);
System.out.println(result);
}
}
然后就会报错,具体报错信息:
DEBUG: setDebug: JavaMail version 1.4ea
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.qq.com", port 25, isSSL false
DEBUG SMTP: exception reading response: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
javax.mail.MessagingException: Exception reading response;
  nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1462)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1260)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:370)
at javax.mail.Service.connect(Service.java:297)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at com.techown.lib.mail.Mail.send(Mail.java:134)
at com.techown.lib.mail.Mail.send(Mail.java:139)
at Test.TestSendMail.sendEmail(TestSendMail.java:13)
at Test.TestSendMail.main(TestSendMail.java:25)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(InputRecord.java:523)
at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:355)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1112)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:744)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:97)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:75)
at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1440)
... 11 more
false高手帮忙看下哪地方出错了