下面代码中的TO来自于数据库。Properties props = System.getProperties();
    
    if (mailhost != null)
props.put("mail.smtp.host", mailhost);     // Get a Session object
    Session session = Session.getDefaultInstance(props, null);
   
    // construct the message
    Message msg = new MimeMessage(session);
    if (from != null)
msg.setFrom(new InternetAddress(from));
    else
msg.setFrom();     msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));
    if (cc != null)
msg.setRecipients(Message.RecipientType.CC,
InternetAddress.parse(cc, false));
    if (bcc != null)
msg.setRecipients(Message.RecipientType.BCC,
InternetAddress.parse(bcc, false));     msg.setSubject(subject);
msg.setText("this is the first sample");
    msg.setHeader("X-Mailer", mailer);
    msg.setSentDate(new Date());     // send the thing off
    Transport.send(msg);     System.out.println("\nMail was sent successfully.");