aspose file tools
The moose likes Other JSE/JEE APIs and the fly likes Sending an email using JMS Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply Bookmark "Sending an email using JMS" Watch "Sending an email using JMS" New topic
Author

Sending an email using JMS

Sam Islam
Greenhorn

Joined: Mar 12, 2002
Posts: 10
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
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 11862
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


Java Resources at www.wbrogden.com
Sam Islam
Greenhorn

Joined: Mar 12, 2002
Posts: 10
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.
Brent Worden
Ranch Hand

Joined: Nov 26, 2001
Posts: 50
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.


Brent Worden
Peter Wood
Greenhorn

Joined: Apr 03, 2002
Posts: 1
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

Joined: Mar 12, 2002
Posts: 10
Thanks for your help guys, it's really appreciated.
Robert Troshynski
Greenhorn

Joined: Jan 11, 2002
Posts: 16
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


Robert Troshynski
 
 
subject: Sending an email using JMS
 
Threads others viewed
JMS Server
Configuration of WAS6.0.1 JMS provider!
Authenticating MQ JMS Connection
How to use JMS MESSAHE SELECTOR
Message driven bean instance pool and concurrent proceesing
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture