SMTP 测量和评估
SMTP measurement and evaluation
我正在尝试了解 SMTP 的工作原理 (JAVAMAIL API)。
我编写了一个代码,可以将消息发送到给定的地址列表。
我用作 SMTP 服务器的属性:
mail.smtp.auth= true
mail.smtp.starttls.enable= true
mail.smtp.host= smtp.gmail.com
mail.smtp.port= 587
发送电子邮件代码是:
public void sendEmail(String emailRecip, String subject, String texte) {
boolean isMsgSent = false;
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
String address = emailRecip;
InternetAddress[] iAdressArray = InternetAddress.parse(address);
message.setRecipients(Message.RecipientType.TO,iAdressArray);
message.setSubject(subject);
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(texte);
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
message.setContent(mp);
Transport.send(message);
isMsgSent = true;
} catch (MessagingException e) {
//...
}
}
此代码运行良好,但我想知道如何:
1- calculate the avrage time of message delivery
2- calculate the impact of the size of the message
3- evaluate the impact of sending multiple messages on the same SMTP
我发现很多文档都在谈论这些问题,但我不知道如何将其放入代码示例中,是否有任何其他属性我必须将其添加到 SMTP 服务器?
JavaMail 不会为您做这件事。您将需要一些性能分析工具。找到一个你喜欢的,然后将它应用到这个任务中。或者自己做一些简单的事情,使用 System.currentTimeMillis() 来测量操作所花费的时间。
另请参阅此 JavaMail FAQ entry for sending multiple messages with a single connection。
我正在尝试了解 SMTP 的工作原理 (JAVAMAIL API)。
我编写了一个代码,可以将消息发送到给定的地址列表。
我用作 SMTP 服务器的属性:
mail.smtp.auth= true
mail.smtp.starttls.enable= true
mail.smtp.host= smtp.gmail.com
mail.smtp.port= 587
发送电子邮件代码是:
public void sendEmail(String emailRecip, String subject, String texte) {
boolean isMsgSent = false;
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(username));
String address = emailRecip;
InternetAddress[] iAdressArray = InternetAddress.parse(address);
message.setRecipients(Message.RecipientType.TO,iAdressArray);
message.setSubject(subject);
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(texte);
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);
message.setContent(mp);
Transport.send(message);
isMsgSent = true;
} catch (MessagingException e) {
//...
}
}
此代码运行良好,但我想知道如何:
1- calculate the avrage time of message delivery
2- calculate the impact of the size of the message
3- evaluate the impact of sending multiple messages on the same SMTP
我发现很多文档都在谈论这些问题,但我不知道如何将其放入代码示例中,是否有任何其他属性我必须将其添加到 SMTP 服务器?
JavaMail 不会为您做这件事。您将需要一些性能分析工具。找到一个你喜欢的,然后将它应用到这个任务中。或者自己做一些简单的事情,使用 System.currentTimeMillis() 来测量操作所花费的时间。
另请参阅此 JavaMail FAQ entry for sending multiple messages with a single connection。