Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaMail: Manipulating the FROM attribute in one session

Paul Sturrock
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's an FAQ in the Sun site which says:

Q: How can I explicitly set the SMTP FROM: attribute when sending a message?
A: The mail.smtp.from property can be used to set the SMTP FROM: attribute. If this property if absent, the message's From attribute is used. If multiple threads need to send mail simultaneously, and each needs to set the From attribute, each thread should use its own Session object with its own Properties object. The mail.smtp.from property can then be set on each Properties object for each Session (and thus each thread) independently.

It doesn't look like this is a complete ban on manipulating the FROM attribute if you were to have many threads sending many emails with the one Transport (and so Session). I know that there's nothing in SMTP to stop me manipulating the from attribute during one connection. Can anyone think of any reason why Java Mail doesn't want you to do this? Or has anyone done this? Given establishing a connection is expensive, I'd like to reuse the Transport object to send all our applications mail.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic