Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get To/CC/BCC addresses from a MimeMessage?

I need to get the To/CC/BCC addresses from a JavaMail MimeMessage object. It seems that the only way I can do this is through getRecepients, but then I can't tell who's in the To field vs the CC and BCC fields. Is there a way to do this?

like image 478
Naftuli Kay Avatar asked Jan 05 '12 18:01

Naftuli Kay


2 Answers

getRecipients

public Address[] getRecipients(Message.RecipientType type) throws 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"
like image 142
Perception Avatar answered Oct 23 '22 14:10

Perception


Note that you'll never find Bcc recipients on a message you receive, that's the whole point of "Bcc".

like image 9
Bill Shannon Avatar answered Oct 23 '22 14:10

Bill Shannon