Question

The application is running on Jboss server and using JNDI for getting email session. What I am trying to do is sending email to different address than passed to email api.

Application is passing recipient email address like:

PREFIX_email@example.com

I would like to strip PREFIX_ before sending the message. Preferable solution needs to be as transparent as possible.

Is there any ready to use solution for such case? What is best way of handling that?

No correct solution

OTHER TIPS

If you can change the Session properties to redirect the email to another server, you have three choices:

  1. Configure the other server to dump all messages into a single INBOX, then write a JavaMail program to fetch the messages from the INBOX, modify the email addresses, and send the modified message to the real SMTP server.

  2. Write a "fake" SMTP server the accepts the message, rewrites the email addresses, and sends the message to the real SMTP server. You could use JavaMail to help with this.

  3. Configure the SMTP server to do the address rewriting for you before forwarding the message. sendmail can certain do this, I don't know about others.

If you need it for development purpose I can recommend you a good solution for mocking javax.mail.Session.

A github project javaMail extension adds file transport that allows to:

  • save mails to files in text format instead of sending them
  • save mails to files in mbox format instead of sending them
  • add log info instead of sending email
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top