ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Sending E-Mail thru Java Compute Node.

Post new topic  Reply to topic
 Sending E-Mail thru Java Compute Node. « View previous topic :: View next topic » 
Author Message
tom_hanks
PostPosted: Sun May 28, 2006 11:56 pm    Post subject: Sending E-Mail thru Java Compute Node. Reply with quote

Apprentice

Joined: 19 May 2006
Posts: 32

Hai...

I need to send e-mail with Java Node.

I have written Core Java code to send E-Mail. Code is attached.
It is working on windows.
But When itried to put in Java Node It is not deploying in to broker.

Is there any thing else to send mail from java.

Code:
import java.util.*;
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

class SendMailUdf
{
   public static int sendMail(String to, String from, String host, String subj, String message) throws Exception
   {
      StringTokenizer st = new StringTokenizer(to, ";");
      Vector v = new Vector();
      int cnt = 0;
      while (st.hasMoreTokens())
      {
         v.addElement(st.nextToken());
         cnt++;
      }

      InternetAddress[] address = new InternetAddress[cnt];
      Enumeration enum1 = v.elements();
for (int i=0; i<cnt; i++)
         address[i] = new InternetAddress(((String) enum1.nextElement()).trim());
         String myname = "Dheeraj is the best!!";
      Properties props = new Properties();
      props.put("mail.smtp.host", host);
      Session session = Session.getDefaultInstance(props, null);
      // create a message
      MimeMessage mimemessage = new MimeMessage(session);
      MimeBodyPart mimebodypart = new MimeBodyPart();
      mimebodypart.setContent(message, "text/html");
      MimeMultipart mimemultipart = new MimeMultipart();
      mimemultipart.setSubType("alternative");
      mimemultipart.addBodyPart(mimebodypart);
      mimemessage.setFrom(new InternetAddress(from));
      mimemessage.setRecipients(javax.mail.Message.RecipientType.TO, address);
      mimemessage.setSubject(subj);
      mimemessage.setSentDate(new Date());
      mimemessage.setContent(mimemultipart);
        Transport.send(mimemessage);
      return 0;
   }

   public static void main(String[] arg)
   {
      try
      {
         SendMailUdf.sendMail("kevin@abcd.com", "kevin@abcd.com", "smtp", "Hi! From WBIMB", "Successful!!!");
      }
      catch (Exception ex)
      {
         ex.printStackTrace();
      }
      System.exit(0);
   }
}
Back to top
View user's profile Send private message
elvis_gn
PostPosted: Sun May 28, 2006 11:59 pm    Post subject: Reply with quote

Padawan

Joined: 08 Oct 2004
Posts: 1905
Location: Dubai

Hi tom_hanks,

Why dont u use the send mail plugin which is free for download on the IBM site ?

Regards.
Back to top
View user's profile Send private message Send e-mail
tom_hanks
PostPosted: Mon May 29, 2006 12:47 am    Post subject: Reply with quote

Apprentice

Joined: 19 May 2006
Posts: 32

Yes Elvis.

you are right. But I am converting Html to Pdf in Java node and need to mail there itself.

thats why i need customized java node.

and one more thing is that, some times i need to send message as Html page (in sendmailplugin, it is sending as plain text only)

some experties look into the java code.

thanks in advance.
Tom
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Mon May 29, 2006 2:43 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

I don't think anything's wrong with your code.
Just make sure javax.mail.jar and javax.activation.jar are on your classpath.
Note sometimes javax.activation is contained in javax.mail.jar.

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
jefflowrey
PostPosted: Mon May 29, 2006 4:36 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

What do you mean "not deploying to broker"?

How is it "not deploying"? What errors do you get? How did you repackage this code to be useable from broker instead of as a standalone java application? As a java procedure? As a Java compute node? As a custom plugin?
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
tom_hanks
PostPosted: Mon May 29, 2006 7:56 pm    Post subject: Reply with quote

Apprentice

Joined: 19 May 2006
Posts: 32

Hai fjb_saper,

Yes. Class path contains both the jar files. it compiling and forming as .jar file in .Bar file. So i think no compilation problem.

If i run as stand alone java application in message broker, it is able to send e-mails. Its not getting deployed to execution group if embed as part of message flow in java node.

Hai jefflowrey,

I placed this code in Java Compute Node. If this is not the right way, please let me know where to place the code. Because I am new to Message broker with java code.

my main objective is to e-mail the message output in message flow.
so i think i need to to do it in java compute node only.
update me on other methods also.

"not deploying" means .jar is not getting deployed into Execution group from .Bar files.

errors as in Event log is
Code:
BIP4368S: The method 'setAttribute' has thrown the following exception: com.ibm.broker.javacompute.MbRuntimeJavaComputeNode$MbJCNDeployException.

The Java API framework has caught an unhandled Java exception.

Contact the node provider for further details.

BIP4395E: Java exception: 'com.ibm.broker.javacompute.MbRuntimeJavaComputeNode$MbJCNDeployException'; thrown from class name: 'com.ibm.broker.javacompute.MbRuntimeJavaComputeNode', method name: 'updateNodeClass', file: 'MbRuntimeJavaComputeNode.java', line: '216'

The message contains that data associated with a Java exception.

No user action required.


thanks a lot,
Tom
Back to top
View user's profile Send private message
tom_hanks
PostPosted: Mon May 29, 2006 10:20 pm    Post subject: Reply with quote

Apprentice

Joined: 19 May 2006
Posts: 32

Yahooo ... I got solved the problem. solution is that i need to deploy mail.jar file into broker also.

Now one more question.

I need Mail Output and input of Java node.

Can any body give me syntax to store Input , Output to string variable in Java compute node.

thanks
Tom
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue May 30, 2006 5:00 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I'm not quite sure what you mean by "Mail Output and input of Java node".

The Java compute node works the same way as an ESQL compute node does. That is, it doesn't take any arguments passed to it - it only works with Input message trees and creates Ouput message trees.

There are some good Samples available in the Samples gallery. There is good documentation on how to write Java that will access the input message trees, and create the necessary stuff to create the Output message trees.

The API is the same as it is for writing a custom plug-in.

If you want to send "input" and "output" parameters, you can re-package your code as a Java procedure, and then call it that way from ESQL.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
tom_hanks
PostPosted: Tue May 30, 2006 6:23 am    Post subject: Reply with quote

Apprentice

Joined: 19 May 2006
Posts: 32

Hai jefflowrey.

you got my problem exactly. I need to do some operations with input message tree.

for e.g., in ESQL I can play(adding, deleting , manipulate some tags) with OutputRoot.XML.... like this i need to do it in Java Node also. I need the syntax to do the same in java node.

I found in default code formed by clicking Open Java (as "Filter Node") outAssembly, it is some thing like OutputRoot. If not, please give syntax for manipulate OutputRoot.

and also let me know how to create and call java repackage from ESQL.

thanks a lot.
Tom
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Tue May 30, 2006 6:49 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

The documentation for the different classes in the Java API is the same for Java Compute nodes as it is for Java plugins.

Start here:
http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r0m0/index.jsp?topic=/com.ibm.etools.mft.doc/ac30200_.htm

Then for reference use
http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r0m0/index.jsp?topic=/com.ibm.etools.mft.doc/com/ibm/broker/plugin/package-overview.html

And, again, there is a sample in the Samples Gallery (installed on your machine!) for the Java Compute Node. You should examine the code of that.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
tom_hanks
PostPosted: Wed May 31, 2006 12:42 am    Post subject: Reply with quote

Apprentice

Joined: 19 May 2006
Posts: 32

Sure jefflowrey.

I am followinig those references.
thanks a lot.

-Tom
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Sending E-Mail thru Java Compute Node.
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.