Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Sending an email using JMS

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anyone help me? I am using JDK1.3 and J2sdkee1.2.1 and have constructed an email message using JavaMail. Now I need to put the email onto a point-to-point JMS queue. Is there a way I can this. I know this is possible with EJB 2.0 using message driven beans, but this is not an option for me.
I'll appreciate any help you can give me.
Thanks
Sam
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can certainly write the complete text of the email into a JSM TextMessage. Alternately maybe you could serialize the Message object and send it as an ObjectMessage.
I guess it depends on what is supposed to pick the message up on the other end.
Bill
 
Sam Islam
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill, but need to pick your brain some more...
Do I need to format the recipient, the subject and the message parts of the email in a particular way when I send it as a TextMessage?
It is already constructed using JavaMail, but will it get 'broken down' to one long string by sending it as a TextMessage? I don't understand how it will be constructed back into an email? The email will sit in a queue on a server, and so long as the connection out is fine, the email will be sent, otherwise it will sit in the queue until the connection resumes at which point it will be sent to the recipient.
Hope this makes sense and you can enlighten me some more.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javax.mail.Message objects are not serializable. So, sending it wrapped inside a javax.jms.ObjectMessage is out of the question.
As for the javax.jms.TextMessage, having the client create a javax.mail.Message, then extract its full text (headers and body), then place the text on the queue just to have the queue consumer create a javax.mail.Message from the text and finally send the email, seems a bit bass ackwords.
I would suggest moving the javax.mail.Message creation logic to the queue consumer. Your client would create a javax.jms.Message with all the raw data (recipients, sender, headers, body, ...) that the queue consumer needs to create the javax.mail.Message. The queue consumer, upon receiving a message will extract the raw data from the javax.jms.Message, construct the javax.mail.Message from this data, and finally send the email.
The transmitting of the raw data could either be done with javax.jms.ObjectMessage with a custom, serializable, dumb data bean that holds all the raw data as its payload.
Or you could use the javax.jms.MapMessage to store all the raw data.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look, I'll give it to you straight :-)
JMS has got absolutely nothing to do with email. It doesn't know about JavaMail or email formats or anything. I want to make this clear. You are going to have to decide and implement a way of sending a normal TextMessage (yes, just a plain old Java String) to send the email and 'unravel' back into the format you want at the other end.
I can understand you not understanding how it will be constructed back into an email - because it won't! unless you do it, manually.
I am assuming that the comment about javax.mail.Message (?) objects not being serializable made earlier, is valid. Otherwise you could send an ObjectMessage on the queue.

Originally posted by Sam Islam:
I don't understand how it will be constructed back into an email?


[ April 03, 2002: Message edited by: Peter Wood ]
 
Sam Islam
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help guys, it's really appreciated.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With respect to JavaMail, there are some articles about sending and receiving email using the JavaMail API (with code examples) at the following URL:
http://developer.java.sun.com/developer/JDCTechTips/
I hope this is of some use.
Bob Troshynski
 
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic