һ jar  <dependency> 
    <groupId>com.sun.mail</groupId> 
    <artifactId>javax.mail</artifactId> 
    <version>1.5.6</version> 
</dependency> 
 
ڶʵ(ֱӸƣ˺滻Ϊͷ smtp ˺ż) ʼʵ

import java.util.List; 
import java.util.Properties; 
import com.sun.mail.util.MailSSLSocketFactory; 
 
/** 
 * ʼòϢ 
 * @ClassName: MailSenderInfo  
 * @Description: TODO 
 * @author umail 
 * @Date 2019  5  8   6:27:35   
 * 
 */ 
public class MailSenderInfo { 
    // ʼķ IP 
    private String mailServerHost; 
    //ʼķ˿ڣôʱĬ 25 
    private String mailServerPort = "25"; 
    // ʼߵĵַ 
    private String fromAddress; 
    // ʼߵĵַ 
    private String toAddress; 
    //ʼߵĵַ 
    private String[] toBatchAddress; 
    // ½ʼͷû 
    private String userName; 
    //½ʼͷ 
    private String password; 
    // ǷҪ֤ [Ĭ false ֤] 
    private boolean validate = false; 
    // ʼ 
    private String subject; 
    // ʼ 
    private String[] subjects; 
    // ʼı 
    private String content; 
    // ʼı 
    private String[] contents; 
    // ʼļ 
    private String[] attachFileNames; 
    // ʼļ һʼϵ 
    private List<String[]> attachFileList; 
    /** 
     * ʼỰ 
     */ 
    public Properties getProperties() { 
        Properties p = new Properties(); 
        try { 
            p.put("mail.smtp.host", this.mailServerHost); 
            p.put("mail.smtp.port", this.mailServerPort); 
            p.put("mail.smtp.auth", validate ? "true" : "false"); 
            p.setProperty("mail.transport.protocol", "smtp"); 
            if("smtp.qq.com".equals(this.mailServerHost)) { 
                MailSSLSocketFactory sf = new MailSSLSocketFactory(); 

                sf.setTrustAllHosts(true); 
                p.put("mail.smtp.ssl.enable", "true"); 
                p.put("mail.smtp.ssl.socketFactory", sf); 
            } 
        }catch (Exception e) { 
            e.printStackTrace(); 
        } 
        return p; 
    } 
    /** 
     * ʼķ IP  磺smtp.bestedm.net 
     */ 
    public String getMailServerHost() { 
        return mailServerHost; 
    } 
    /** 
     * ʼķ IP  磺smtp.bestedm.net 
     */ 
    public void setMailServerHost(String mailServerHost) { 
        this.mailServerHost = mailServerHost; 
    } 
    /** 
     * ʼķ˿ڣ磺umail Ĭ 25 
     */ 
    public String getMailServerPort() { 
        return mailServerPort; 
    } 
    /** 
     * ʼķ˿ڣ磺Ĭ 25 
     */ 
    public void setMailServerPort(String mailServerPort) { 
        this.mailServerPort = mailServerPort; 
    } 
    /** 
     * ǷҪ֤ [Ĭ false ֤] 
     */ 
    public boolean isValidate() { 
        return validate; 
    } 
    /** 
     * ǷҪ֤ [Ĭ false ֤] 
     */ 
    public void setValidate(boolean validate) { 
        this.validate = validate; 
    } 
    /** 
     * ʼļ 
     */ 
    public String[] getAttachFileNames() { 
        return attachFileNames; 
    } 
    /** 
     * ʼļ 
     */ 
    public void setAttachFileNames(String[] fileNames) { 
        this.attachFileNames = fileNames; 
    } 
    /** 
     * ʼߵַ 
     */ 
    public String getFromAddress() { 
        return fromAddress; 
    } 
    /** 
     * ʼߵַ 
     */ 
    public void setFromAddress(String fromAddress) { 
        this.fromAddress = fromAddress; 
    } 
    /** 
     * ʼߵ 
     */ 
    public String getPassword() { 
        return password; 
    } 
    /** 
     * ʼߵ 
     */ 
    public void setPassword(String password) { 
        this.password = password; 
    } 
    /** 
     * ʼߵĵַ 
     */ 
    public String getToAddress() { 
        return toAddress; 
    } 
    /** 
     * ʼߵĵַ 
     */ 
    public void setToAddress(String toAddress) { 
        this.toAddress = toAddress; 
    } 
    /** 
     * ʼߵĵַ 
     * @return 
     */ 
    public String[] getToBatchAddress() { 
        return toBatchAddress; 
    } 
    /** 
     * ʼߵĵַ 
     * @param toBatchAddress 
     */ 
    public void setToBatchAddress(String[] toBatchAddress) { 
        this.toBatchAddress = toBatchAddress; 
    } 
    /** 
     * ½ʼͷû 
     */ 
    public String getUserName() { 
        return userName; 
    } 
    /** 
     * ½ʼͷû 
     */ 
    public void setUserName(String userName) { 
        this.userName = userName; 
    } 
    /** 
     * ʼ 
     */ 
    public String getSubject() { 
        return subject; 
    } 
    /** 
     * ʼ 
     */ 
    public void setSubject(String subject) { 

        this.subject = subject; 
    } 
    /** 
     * ʼ 
     */ 
    public String[] getSubjects() { 
        return subjects; 
    } 
    /** 
     * ʼ 
     */ 
    public void setSubjects(String[] subjects) { 
        this.subjects = subjects; 
    } 
    /** 
     * ʼı 
     */ 
    public String getContent() { 
        return content; 
    } 
    /** 
     * ʼı 
     */ 
    public void setContent(String textContent) { 
        this.content = textContent; 
    } 
    /** 
     * ʼı 
     */ 
    public String[] getContents() { 
        return contents; 
    } 
    /** 
     * ʼı 
     */ 
    public void setContents(String[] contents) { 
        this.contents = contents; 
    } 
    /** 
     * һʼ฽ 
     */ 
    public List<String[]> getAttachFileList() { 
        return attachFileList; 
    } 
    /** 
     * һʼ฽ 
     */ 
    public void setAttachFileList(List<String[]> attachFileList) { 
        this.attachFileList = attachFileList; 
    } 
     
     
} 
 
ʼ֤ 
 
import javax.mail.Authenticator; 
import javax.mail.PasswordAuthentication; 
 
/** 
 *  
 * @ClassName: MailAuthenticator  
 * @Description: TODO 
 * @author umail 
 * @Date 2019  5  8   6:22:59   
 * 
 */ 
public class MailAuthenticator extends Authenticator{    
    String userName=null;    
    String password=null;    
         
    public MailAuthenticator(){    
    }    
    public MailAuthenticator(String username, String password) {     
        this.userName = username;     
        this.password = password;     
    }     
    protected PasswordAuthentication getPasswordAuthentication(){    
        return new PasswordAuthentication(userName, password);    
    }    
} 
 
 
ʼ 
 
import java.io.UnsupportedEncodingException; 
import java.util.Date; 
import java.util.Properties; 
 
import javax.activation.DataHandler; 
import javax.activation.FileDataSource; 
import javax.mail.Address; 
import javax.mail.BodyPart; 
import javax.mail.Message; 
import javax.mail.MessagingException; 
import javax.mail.Multipart; 
import javax.mail.NoSuchProviderException; 
import javax.mail.Session; 
import javax.mail.Transport; 
import javax.mail.internet.AddressException; 
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; 
 
/** 
 * ʼ 
 * @ClassName: SimpleMailSender  
 * @Description: TODO 
 * @author umail 
 * @Date 2019  5  8   6:23:20   
 * 
 */ 
public class SimpleMailSender { 
 
    /** 
     * ıʽʼ 
     *  
     * @param mailInfo 
     *            ͵ʼϢ 
     */ 
    public boolean sendTextMail(MailSenderInfo mailInfo) { 
        // жǷҪ֤ 
        MailAuthenticator authenticator = null; 
        Properties pro = mailInfo.getProperties(); 
        if (mailInfo.isValidate()) { 
            // Ҫ֤򴴽һ֤ 
            authenticator = new MailAuthenticator(mailInfo.getUserName(), 
U-Mail Ⱥƽ̨ | ͷ 400-8181-568 
 
78 
ѡ U-Mail ѡЧ ѡƷ 
                    mailInfo.getPassword()); 
        } 
        // ʼỰԺ֤һʼ session 
        Session sendMailSession = Session 
                .getDefaultInstance(pro, authenticator); 
        try { 
            //  session һʼϢ 
            Message mailMessage = new MimeMessage(sendMailSession); 
            // ʼߵַ 
            Address from = new InternetAddress(mailInfo.getFromAddress()); 
            // ʼϢķ 
            mailMessage.setFrom(from); 
            // ʼĽߵַõʼϢ 
            if (mailInfo.getToAddress() != null 
                    && mailInfo.getToAddress().length() > 0) { 
                Address to = new InternetAddress(mailInfo.getToAddress()); 
                // Message.RecipientType.TO ԱʾߵΪ TO 
                mailMessage.setRecipient(Message.RecipientType.TO, to); 
            } else if (mailInfo.getToBatchAddress() != null 
                    && mailInfo.getToBatchAddress().length > 0) { 
                final int size = mailInfo.getToBatchAddress().length; 
                Address[] to = new Address[size]; 
                for (int i = 0; i < size; i++) { 
                    to[i] = new InternetAddress(mailInfo.getToBatchAddress()[i]); 
                } 
                // Message.RecipientType.TO ԱʾߵΪ TO 
                mailMessage.setRecipients(Message.RecipientType.TO, to); 
            } 
            // ʼϢ 
            mailMessage.setSubject(mailInfo.getSubject()); 
            // ʼϢ͵ʱ 
            mailMessage.setSentDate(new Date()); 
            // ʼϢҪ 
            String mailContent = mailInfo.getContent(); 
            mailMessage.setText(mailContent); 
            // ʼ 
            Transport.send(mailMessage); 
            return true; 
        } catch (MessagingException ex) { 
            ex.printStackTrace(); 
        } 
        return false; 
    } 

 
    /** 
     *  HTML ʽʼ 
     *  
     * @param mailInfo 
     *            ͵ʼϢ 
     */ 
    public boolean sendHtmlMail(MailSenderInfo mailInfo) { 
        // жǷҪ֤ 
        MailAuthenticator authenticator = null; 
        Properties pro = mailInfo.getProperties(); 
        // Ҫ֤򴴽һ֤ 
        if (mailInfo.isValidate()) { 
            authenticator = new MailAuthenticator(mailInfo.getUserName(), 
                    mailInfo.getPassword()); 
        } 
        // ʼỰԺ֤һʼ session 
        Session sendMailSession = Session 
                .getDefaultInstance(pro, authenticator); 
        try { 
            sendMailSession.setDebug(true); 
            //  session һʼϢ 
            Message mailMessage = new MimeMessage(sendMailSession); 
            // ʼߵַ 
            Address from = new InternetAddress(mailInfo.getFromAddress()); 
            // ʼϢķ 
            mailMessage.setFrom(from); 
            // ʼĽߵַõʼϢ 
            if (mailInfo.getToAddress() != null 
                    && mailInfo.getToAddress().length() > 0) { 
                Address to = new InternetAddress(mailInfo.getToAddress()); 
                // Message.RecipientType.TO ԱʾߵΪ TO 
                mailMessage.setRecipient(Message.RecipientType.TO, to); 
            } else if (mailInfo.getToBatchAddress() != null 
                    && mailInfo.getToBatchAddress().length > 0) { 
                final int size = mailInfo.getToBatchAddress().length; 
                Address[] to = new Address[size]; 
                for (int i = 0; i < size; i++) { 
                    to[i] = new InternetAddress(mailInfo.getToBatchAddress()[i]); 
                } 
                // Message.RecipientType.TO ԱʾߵΪ TO 
                mailMessage.setRecipients(Message.RecipientType.TO, to); 
            } 
 
            // ʼϢ 
            mailMessage.setSubject(mailInfo.getSubject()); 
            mailMessage.setSubject(MimeUtility.encodeText(mailInfo.getSubject(), "UTF-8", 
"B")); 
            // ʼϢ͵ʱ 
            mailMessage.setSentDate(new Date()); 
            // MiniMultipart һ࣬ MimeBodyPart ͵Ķ 
            Multipart mainPart = new MimeMultipart(); 
             
            //-------------------------------beigin ı---------------------//             
            // һ HTML ݵ MimeBodyPart 
            BodyPart html = new MimeBodyPart(); 
            //  HTML  
            html.setContent(mailInfo.getContent(), "text/html; charset=utf-8"); 
            mainPart.addBodyPart(html); 
            //----------------------------------end ı---------------------// 
             
             
            //-------------------------------beigin ---------------------// 
            if(mailInfo.getAttachFileList() != null && mailInfo.getAttachFileList().size() > 
0){ 
                for (String[] files : mailInfo.getAttachFileList()) { 
                    for (String file : files) { 
                        //ʼĸ 
                        String fileName = file; 
                        if(fileName != null&&!fileName.trim().equals("")) { 
                            MimeBodyPart mbp = new MimeBodyPart();                     
                            FileDataSource fileSource = new FileDataSource(fileName); 
                            mbp.setDataHandler(new DataHandler(fileSource)); 
                            try { 
                                
mbp.setFileName(MimeUtility.encodeText(fileSource.getName())); 
                            } catch (UnsupportedEncodingException e) { 
                                e.printStackTrace(); 
                            } 
                            mainPart.addBodyPart(mbp); 
                        } 
                    } 
                } 
            } else { 
                if(mailInfo.getAttachFileNames() != null && 
mailInfo.getAttachFileNames().length > 0){ 
                    //ʼĸ 

                    String fileName = mailInfo.getAttachFileNames()[0]; 
                    if(fileName != null&&!fileName.trim().equals("")) { 
                        MimeBodyPart mbp = new MimeBodyPart();                     
                        FileDataSource fileSource = new FileDataSource(fileName); 
                        mbp.setDataHandler(new DataHandler(fileSource)); 
                        try { 
                            mbp.setFileName(MimeUtility.encodeText(fileSource.getName())); 
                        } catch (UnsupportedEncodingException e) { 
                            e.printStackTrace(); 
                        } 
                        mainPart.addBodyPart(mbp); 
                    } 
                } 
            } 
             
            //----------------------------------end ---------------------// 
             
             
            //  MiniMultipart Ϊʼ 
            mailMessage.setContent(mainPart); 
            // ʼ 
            Transport.send(mailMessage); 
            System.out.println("ͳɹ"); 
            return true; 
        } catch (MessagingException ex) { 
            ex.printStackTrace(); 
        } catch (UnsupportedEncodingException e1) { 
            // TODO Auto-generated catch block 
            e1.printStackTrace(); 
        } 
        return false; 
    } 
 
    /** 
     *  HTML ʽͶʼ 
     *  
     * @param mailInfo 
     *            ͵ʼϢ 
     */ 
    public boolean sendBatchHtmlMail(MailSenderInfo mailInfo)  { 
        // жǷҪ֤ 
        MailAuthenticator authenticator = null; 
        Properties pro = mailInfo.getProperties(); 

        pro.setProperty("mail.transport.protocol", "smtp"); 
        // Ҫ֤򴴽һ֤ 
        if (mailInfo.isValidate()) { 
            authenticator = new MailAuthenticator(mailInfo.getUserName(), 
                    mailInfo.getPassword()); 
        } 
        // ʼỰԺ֤һʼ session 
        Session sendMailSession = Session.getInstance(pro, authenticator);         
        try {             
            // ʼ 
            sendMailSession.setDebug(true); 
            Transport transport = sendMailSession.getTransport(); 
            
transport.connect(mailInfo.getMailServerHost(),Integer.parseInt(mailInfo.getMailServerPort()
), 
                    mailInfo.getUserName(), mailInfo.getPassword()); 
            // ʼĽߵַõʼϢ 
            if (mailInfo.getToBatchAddress() != null 
                    && mailInfo.getToBatchAddress().length > 0) {                     
                final int size = mailInfo.getToBatchAddress().length;                     
                for (int i = 0; i < size; i++) { 
                    //  session һʼϢ 
                    Message mailMessage = new MimeMessage(sendMailSession); 
                    // ʼߵַ 
                    Address from = new InternetAddress(mailInfo.getFromAddress()); 
                    // ʼϢķ 
                    mailMessage.setFrom(from);                     
                     
                    // ʼϢ 
                    mailMessage.setSubject(mailInfo.getSubjects()[i]); 
                    mailMessage.setSubject(MimeUtility.encodeText(mailInfo.getSubjects()[i], 
"UTF-8", "B")); 
                    // ʼϢ͵ʱ 
                    mailMessage.setSentDate(new Date()); 
                    // MiniMultipart һ࣬ MimeBodyPart ͵Ķ 
                    Multipart mainPart = new MimeMultipart(); 
                     
                    //-------------------------------beigin ı---------------------// 
                    // һ HTML ݵ MimeBodyPart 
                    BodyPart html = new MimeBodyPart(); 
                    //  HTML  
                    html.setContent(mailInfo.getContents()[i], "text/html; charset=utf-8"); 
                    mainPart.addBodyPart(html); 

                    //----------------------------------end ı---------------------// 
                     
                    //-------------------------------beigin ---------------------// 
                    if(mailInfo.getAttachFileList() != null && 
mailInfo.getAttachFileList().size() > 0){ 
                        String[] files = mailInfo.getAttachFileList().get(i); 
                        for (String file : files) { 
                            //ʼĸ 
                            String fileName = file; 
                            if(fileName != null&&!fileName.trim().equals("")) { 
                                MimeBodyPart mbp = new MimeBodyPart();                     
                                FileDataSource fileSource = new FileDataSource(fileName); 
                                mbp.setDataHandler(new DataHandler(fileSource)); 
                                try { 
                                    
mbp.setFileName(MimeUtility.encodeText(fileSource.getName())); 
                                    //System.out.println("ceshi2: " + 
MimeUtility.encodeText(fileSource.getName(),"utf-8",null)); 
                                } catch (UnsupportedEncodingException e) { 
                                    e.printStackTrace(); 
                                } 
                                mainPart.addBodyPart(mbp); 
                            } 
                        }                         
                    } else { 
                        if(mailInfo.getAttachFileNames() != null && 
mailInfo.getAttachFileNames().length > 0){ 
                            //ʼĸ 
                            String fileName = mailInfo.getAttachFileNames()[i]; 
                            if(fileName != null&&!fileName.trim().equals("")) { 
                                MimeBodyPart mbp = new MimeBodyPart();                             
                                FileDataSource fileSource = new FileDataSource(fileName); 
                                mbp.setDataHandler(new DataHandler(fileSource)); 
                                try { 
                                    
mbp.setFileName(MimeUtility.encodeText(fileSource.getName())); 
                                    //System.out.println("ceshi: " + 
MimeUtility.encodeText(fileSource.getName(),"utf-8",null)); 
                                } catch (UnsupportedEncodingException e) { 
                                    e.printStackTrace(); 
                                } 
                                mainPart.addBodyPart(mbp); 
                            } 

                        } 
                    } 
                    //----------------------------------end ---------------------// 
                                        
                    //  MiniMultipart Ϊʼ 
                    mailMessage.setContent(mainPart); 
                     
                    Address[] to = new Address[]{new 
InternetAddress(mailInfo.getToBatchAddress()[i])}; 
                    mailMessage.setRecipient(Message.RecipientType.TO, to[0]); 
                    transport.sendMessage(mailMessage, to); 
                }                     
            } 
            transport.close(); 
            System.out.println("ͳɹ"); 
            return true; 
        } catch (AddressException e) { 
            e.printStackTrace(); 
        } catch (NoSuchProviderException e) { 
            e.printStackTrace(); 
        } catch (MessagingException e) { 
            e.printStackTrace(); 
        } catch (UnsupportedEncodingException e) { 
            e.printStackTrace(); 
        } 
         
        return false; 
    } 
} 
 
Դ룺 
import java.util.Date; 
import java.util.Properties; 
import javax.mail.Address; 
import javax.mail.Message; 
import javax.mail.Session; 
import javax.mail.Transport; 
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeMessage;  
import com.only.mate.email.MailAuthenticator; 
import com.only.mate.email.MailSenderInfo; 
import com.only.mate.email.SimpleMailSender; 
import com.sun.mail.util.MailSSLSocketFactory; 
 
public class EmailTest { 
    private MailSenderInfo mailSenderInfo; 
     
    public static void main(String[] args) throws Exception { 
        EmailTest test = new EmailTest(); 
//        test.sendTextEmail1(); 
//        test.sendTextEmail(); 
        test.sendHtmlEmail(); 
    } 
     
    { 
        mailSenderInfo = new MailSenderInfo(); 
        mailSenderInfo.setMailServerHost("smtp.bestedm.net"); 
        mailSenderInfo.setMailServerPort("465"); 
        mailSenderInfo.setUserName("*********@xxx.com"); 
        mailSenderInfo.setPassword("***********"); 
        mailSenderInfo.setFromAddress("********@xxx.com"); 
        mailSenderInfo.setToAddress("********@xxx.com");         
        mailSenderInfo.setValidate(true);         
        mailSenderInfo.setSubject("-²£"); 
        Date date = new Date(); 
        String content = String.format( 
                "<!DOCTYPE html>"+ 
                "<html lang=\"en\">"+ 
                "<head>"+ 
                "<meta charset=\"UTF-8\" />"+ 
                "<title></title>"+ 
                "</head>"+ 
                "<style type=\"text/css\">heml,body{margin: 0;padding: 0;font-size: 
14px;}.container{width: 880px;margin:0 auto;background: #e7f5ff;height:800px;padding-top: 
80px;margin-top: 20px;}.container-con{width:680px;margin:0 
auto;background:#fff;height:600px;padding:20px;}.eamil-top{font-size: 
14px;}.eamil-top>span{color:#000;font-weight: bold;}.eamil-top2{font-size: 14px;padding-left: 
16px;margin-bottom: 30px;}.eamil-con{padding:20px;}.eamil-con>p{line-height: 
20px;}.top-img{background:url(\"images/tt0_03.png\") no-repeat;background-size: cover; 
width:722px;height:100px;margin:0 auto;}.fpptwe{line-height: 30px;}.footer{float: 
right;}.jingao{font-size: 12px;color:#888}</style>"+ 
                "<body>"+ 
                    "<div class=\"container\">"+ 
                        "<div class=\"top-img\"></div>"+ 

                        "<div class=\"container-con\">"+ 
                            "<p class=\"eamil-top\">"+ 
                                "𾴵 XX Ůʿ"+ 
                            "</p>"+ 
                            "<p class=\"eamil-top2\">ã</p>"+ 
                            "<div class=\"eamil-con\">"+ 
                                "<p>ύXXX룬ͨ</p>"+ 
                                "<p>"+ 
                                    "뼰ʱǰȥܣ<span>%s</span>"+ 
                                "</p>"+ 
                                "<img 
src='http://img.mp.itc.cn/upload/20160326/73a64c935e7d4c9594bdf86d76399226_th.jpg' />"+ 
                            "</div>"+ 
                            "<p class=\"jingao\">һϵͳԶ͵ʼ벻Ҫֱӻ
</p>"+ 
                            "<div class=\"footer\">"+ 
                                "<p>ĸ</p>"+ 
                                "<span>%tF %tT</span>"+ 
                            "</div>"+ 
                            "</p>"+ 
                        "</div>"+ 
                    "</div>"+ 
                "</body>"+ 
                "</html>", "??????", date, date); 
        mailSenderInfo.setContent(content); 
//        mailSenderInfo.setContent("ʵֻǺ"); 
         
        mailSenderInfo.setAttachFileNames(new String[] 
{"C:/Users/OnlyMate/Pictures/MyPhoneTheme.jpg"}); 
    } 
    public void sendTextEmail() throws Exception { 
        SimpleMailSender sender = new SimpleMailSender(); 
        sender.sendTextMail(mailSenderInfo); 
    } 
    public void sendHtmlEmail() throws Exception { 
        SimpleMailSender sender = new SimpleMailSender(); 
        sender.sendHtmlMail(mailSenderInfo); 
    } 
    public void sendTextEmail1() throws Exception { 
        Properties props = new Properties(); 
        //  debug  
        props.setProperty("mail.debug", "false"); 
        // ͷҪ֤ 
 

        props.setProperty("mail.smtp.auth", "true"); 
        // ʹ STARTTLS ȫ 
        props.put("mail.smtp.starttls.enable", "true"); 
        // ʼ 
        props.setProperty("mail.smtp.host", mailSenderInfo.getMailServerHost()); 
        // ʼ˿ 
        props.put("mail.smtp.port", mailSenderInfo.getMailServerPort()); 
        // ʼЭ 
        props.setProperty("mail.transport.protocol", "smtp"); 
 
        MailSSLSocketFactory sf = new MailSSLSocketFactory(); 
        sf.setTrustAllHosts(true); 
        props.put("mail.smtp.ssl.enable", "true"); 
        props.put("mail.smtp.ssl.socketFactory", sf); 
 
        // Ҫ֤򴴽һ֤ 
        MailAuthenticator authenticator = new MailAuthenticator(mailSenderInfo.getUserName(), 
                mailSenderInfo.getPassword()); 
        // ʼỰԺ֤һʼ session 
        Session session = Session.getDefaultInstance(props, authenticator); 
 
        Message msg = new MimeMessage(session); 
        msg.setSubject("-²£"); 
        StringBuilder builder = new StringBuilder(); 
        builder.append("ʼ  Java 㷢һʼҵ?յ"); 
        msg.setText(builder.toString()); 
        msg.setFrom(new InternetAddress(mailSenderInfo.getUserName())); 
        Address to = new InternetAddress(mailSenderInfo.getToAddress()); 
        // Message.RecipientType.TO ԱʾߵΪ TO 
        msg.setRecipient(Message.RecipientType.TO, to); 
         
        Transport.send(msg); 
        /*Transport transport = session.getTransport("smtp"); 
        transport.connect(mailSenderInfo.getMailServerHost(),mailSenderInfo.getUserName(), 
"irfydcgrkxembbii"); 
 
        transport.sendMessage(msg, new Address[] { new InternetAddress("*****@qq.com") }); 
        transport.close();*/ 
    } 
} 
 