1

JBoss 4.2.3 に Web アプリがあり、電子メールを送信したいと考えています。私は次のようなことができます:

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 Abstraction Layerを使用します

于 2009-07-07T15:03:47.733 に答える
1

何通のメッセージを送信していますか? 上記の実行にかかる時間を測定しましたか? (主要なタイム シンクは実際send()には MTA にあると想定しています。それが重要かどうかは別の問題です)

多分:

  1. MTA に送信するメッセージをキューに入れ、送信を別のスレッドで実行する必要がありますか?
  2. 適切なメーリング リスト / エイリアスの設定が必要で、'n' 人の受信者にメールを 1 つだけ送信するにはどうすればよいですか?

しかし、それはすべて、送信するメッセージの数と、受信者のセットがどれだけ異なるかにかかっています。

于 2009-07-07T15:03:51.727 に答える