从MimeMessage获取/ CC / BCC地址?

时间:2012-01-05 18:34:25

标签: java javamail

我需要从JavaMail MimeMessage对象获取To / CC / BCC地址。似乎我能做到这一点的唯一方法是通过getRecepients,但后来我无法分辨To字段中的哪个字段与CCBCC字段中的字符。有没有办法做到这一点?

4 个答案:

答案 0 :(得分:13)

  

getRecipients

     

public Address [] getRecipients(Message.RecipientType type)                           抛出MessagingException

Returns the recepients specified by the type. The mapping between the type and the corresponding RFC 822 header is as follows:

                Message.RecipientType.TO                "To"
                Message.RecipientType.CC                "Cc"
                Message.RecipientType.BCC               "Bcc"
                MimeMessage.RecipientType.NEWSGROUPS    "Newsgroups"

答案 1 :(得分:9)

请注意,您永远不会在收到的邮件中找到密送收件人,这就是“密件抄送”的全部内容。

答案 2 :(得分:1)

MimeMessage确实有getRecipients()方法,其输入参数类型为Message.RecipientType。只需使用......

答案 3 :(得分:0)

我对你的问题有答案,这对我很有效。

消息msg = folder.getMessages(1);  地址[] a = m.getRecipients(Message.RecipientType.TO);