开发者

JavaMail Message.reply(boolean) does not populate recipients

I'm trying to write a simple routine to reply to an email with a determined from address and subject, however, for whatever reason the reply method is not populating the recipients.

In the following example rep is always null, any attempt to call Transport.send results in an exception stating there were no recipients.

MimeMessage reply = (MimeMessage) message.reply(false);
Address[] rep = reply.getRecipients(Message.RecipientType.TO);
if (rep == null || rep.length == 0) {
    System.out.println("Reply aborted due to no recipient.");
} else {
    reply.setFrom(from);
    reply.setText(body);
    Transport.send(reply)开发者_如何学Go;
}

I'm applying the pattern that's demonstrated on the Oracle jGuru pages and copied all over the place in various flavours.


From the docs of reply:

If replyToAll is set, the new Message will be addressed to all recipients of this message. Otherwise, the reply will be addressed to only the sender of this message (using the value of the getReplyTo method).

So the logical next step would be to check what message.getReplyTo() returns. If that returns null, it explains the issue...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜