Email 从web应用发送电子邮件的推荐方式?

Email 从web应用发送电子邮件的推荐方式?,email,jboss,jakarta-ee,smtp,jakarta-mail,Email,Jboss,Jakarta Ee,Smtp,Jakarta Mail,我在JBoss4.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("m

我在JBoss4.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);
}

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

使用Spring时,您要发送多少条消息?你有没有测量过上面提到的跑步需要多长时间?(我假设主要的时间消耗将是发送给MTA的实际
send()
。这是否重要是另一回事)

也许:

  • 您需要将要发送到MTA的邮件排入队列,并在单独的线程中运行发送
  • 您需要设置适当的邮件列表/别名,从而只为“n”个收件人发送一封邮件
  • 但这一切都取决于你要发送多少封邮件,以及收件人的不同