我有一个对象,它是一个名为 message 的新 MimeMessage,我想找出它传递给我的外发邮件服务器的内容。然而,我不知道如何在 Java 中打印出这样的变量。这是一些代码:
private String sendConfirmationEmail (String to, String from, String subject, String body, boolean CCSender) {
try
{
// String smtpHost = Properties.smtp;
String smtpHost = Properties.smtp;
String fromAddress = from;
String toAddress = to;
Properties properties = System.getProperties();
properties.put("mail.smtp.host", smtpHost);
Session session = Session.getInstance(properties, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(fromAddress));
message.setRecipient(Message.RecipientType.TO,
new InternetAddress(toAddress));
if (CCSender) {
message.setRecipient(Message.RecipientType.CC,
new InternetAddress(from));
}
message.setSubject(subject);
message.setText(body);
System.out.println(message); <=== I want this to work!
message.saveChanges();
Transport.send(message);
return "1:success";
}
catch(Exception e)
{
return "0:failure "+e.toString();
}
}
任何帮助将非常感激。
谢谢。