• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaMail: How to hide the recipient address?

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

My question is that how to send a message using JavaMail to someone whose email is abc@Domain.com, but it displays to the recipient with a different email address in To field (e.g. xyz@Domain.com)?.
I know the answer is to set:
- RCPT TO: abc@Domain.com
- To: xyz@Domain.com
But how to do it in JavaMail?

Thanks,
Chinh
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
msg = new MimeMessage(session);
msg.addRecipient(Message.RecipientType.TO,new InternetAddress("realadress@domain.com","whatyouwantosee@domain.com"));

hope this helps..
 
Chinh Tran Nam
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Osman,

It looks good at first sight. However, some mail clients (e.g Lotus Notes) display the full recipient address and it reads:
"whatiwhattosee@domain.com" <realaddress@domain.com>
We can set a different evelope address for a simple Socket email, I wonder why we can't do it using JavaMail?

Please advice?
Chinh
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

The SMTP protocol doesn't really use values of To, Cc or any other headers, to determine recipients of the message. When MUA offers an UI to specify the recipients, it merely uses To, Cc, and other fields for both purposes of specifying the values of the corresponding headers, and the destination addresses of the message. JavaMail is merely a MUA (from this point of view). This flaw is greately used by spammers, as you've most likely observed.

There are two ways you can achieve what you need. First, do not set the 'To' header, and use 'Bcc' instead (RecipientType.BCC). That, however, would only result in having NO destination address specified (most likely an MTA will rewrite the 'To' header's value to '; undisclosed recipients'.

Another way, is to set 'To' field in the outgoing message to what you want to be in the header, and then use Transport.send(Message, Address[]) method to deliver the message. In this case, values of the delivery fields in the header (To, Cc, Bcc) will be ignored.
 
reply
    Bookmark Topic Watch Topic
  • New Topic