現在、私はCommons Emailを使用して電子メールメッセージを送信していますが、送信された電子メール間のsmtp接続を共有する方法を見つけることができませんでした。非常に読みやすいですが、私は、各メッセージのために再接続のオーバーヘッドであると信じてメッセージを大量に行うときに遅いApache Commons電子メールとSMTP接続の再利用
Email email = new SimpleEmail();
email.setFrom("[email protected]");
email.addTo("[email protected]");
email.setSubject("Hello Example");
email.setMsg("Hello Example");
email.setSmtpPort(25);
email.setHostName("localhost");
email.send();
:私は、次のようなコードを持っています。そこで私は以下のコードでそれをプロファイリングし、Transportを再利用することで、約3倍高速になります。
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
Session mailSession = Session.getDefaultInstance(props, null);
Transport transport = mailSession.getTransport("smtp");
transport.connect("localhost", 25, null, null);
MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress("[email protected]"));
message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
message.setSubject("Hello Example");
message.setContent("Hello Example", "text/html; charset=ISO-8859-1");
transport.sendMessage(message, message.getAllRecipients());
Commons Emailを複数のメール送信に再利用する方法があるのだろうかと思っていましたか? Commons Email APIの方が気に入っていますが、パフォーマンスは苦しいです。
おかげで、 身代金