1

我在 JBoss 4.2.3 上有一个网络应用程序,我希望它可以发送电子邮件。我可以做类似的事情:

try {
Properties props = System.getProperties();
props.put("mail.transport.protocol", "smtp" );
props.put("mail.smtp.starttls.enable","false" );
props.put("mail.smtp.host","smtp.somehost.com");
props.put("mail.smtp.auth", "true" );
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
// -- Create a new message --
Message msg = new MimeMessage(session);
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress("me@somehost.com"));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("recipient@somewhere.com", false));
msg.setSubject("yadayada");
msg.setText("Yada yada");
// -- Set some other header information --
msg.setHeader("MyMail", "Mr. XYZ" );
msg.setSentDate(new Date());
// -- Send the message --
Transport.send(msg);
}
catch (Exception ex) {
  ex.printStackTrace();
  System.out.println("Exception "+ex);
}

但感觉不对。这会扩展吗?

4

2 回答 2

1

使用 Spring 使用Spring Mail 抽象层

于 2009-07-07T15:03:47.733 回答
1

您要发送多少条消息?您是否测量过上述运行需要多长时间?(我假设主要的时间消耗将在send()MTA 的实际中。这是否重要是另一回事)

也许:

  1. 您需要将要发送到 MTA 的消息排入队列,并让发送在单独的线程中运行?
  2. 您需要设置适当的邮件列表/别名,因此只为“n”个收件人发送一封邮件?

但这一切都取决于您要发送多少条消息,以及接收者的集合有多么不同。

于 2009-07-07T15:03:51.727 回答