Search code examples
javaemailjmsjakarta-mail

Why JMS to send mail by Java Mail


Scenario 1 :

  1. Setup a JMS Queue in your server
  2. Java code to send Messages to Producer Create a JMS Producer, which when invoked, should receive the email data (subject, body, to , cc etc) and post it to the Queue setup in step 1
  3. Create a JMS Consumer, which subscribes to the Queue created in Step 1, and its onMessage should call the JavaMail API to send the email.

Scenario 2 :

  • Directly call the JavaMail API to send the email.

I know about how to use and what JMS and Java Mail are doing.Thing is why we have to go from Scenario 2 to Scenario 1 for sending mails.Initially we did Scenario 2.Now we are using Scenario 1.From Different parts of the Big Application are sending mails so we use JMS Queue ,there will be Consumer of Queue from there sending mails.Please help me to understand.


Solution

  • You would use this mechanism in a large application for 2 reasons:

    1) You don't want your clients to have to wait for the mail to be sent.

    2) You don't want to lose mails if you lose connectivity to your mail server for any reason.