Java:MimeMessage将发送日期设置为多个收件人

时间:2017-05-10 16:29:59

标签: java javamail

如何在向多个收件人发送电子邮件时设置发送日期?我使用setSendData()但在邮件中没有设置日期。

 public class Test {

public static void main(String[] args) throws AddressException {
    java.util.Properties props = new java.util.Properties();
    props.put("mail.smtp.host", "localhost");
    Session session = Session.getDefaultInstance(props, null);

    // Construct the message
    Address[] to = new Address[] {new InternetAddress("abc@abc.com"),
            new InternetAddress("abc@def.com"), 
            new InternetAddress("ghi@abc.com")};
    String from = "me@me.com";
    String subject = "Hello";
    Message msg = new MimeMessage(session);
    try {
        msg.setFrom(new InternetAddress(from));
        msg.setRecipients(Message.RecipientType.TO, to);
        msg.setSubject(subject);
        msg.setSentDate(new Date());
        msg.setText("Hi,\n\nHow are you?");

        // Send the message.
        Transport.send(msg);
    } catch (MessagingException e) {
        // Error.
    }
}}

提前谢谢

0 个答案:

没有答案