Author |
Message
|
tom_hanks |
Posted: Sun May 28, 2006 11:56 pm Post subject: Sending E-Mail thru Java Compute Node. |
|
|
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 |
|
 |
elvis_gn |
Posted: Sun May 28, 2006 11:59 pm Post subject: |
|
|
 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 |
|
 |
tom_hanks |
Posted: Mon May 29, 2006 12:47 am Post subject: |
|
|
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 |
|
 |
fjb_saper |
Posted: Mon May 29, 2006 2:43 am Post subject: |
|
|
 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 |
|
 |
jefflowrey |
Posted: Mon May 29, 2006 4:36 am Post subject: |
|
|
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 |
|
 |
tom_hanks |
Posted: Mon May 29, 2006 7:56 pm Post subject: |
|
|
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 |
|
 |
tom_hanks |
Posted: Mon May 29, 2006 10:20 pm Post subject: |
|
|
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 |
|
 |
jefflowrey |
Posted: Tue May 30, 2006 5:00 am Post subject: |
|
|
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 |
|
 |
tom_hanks |
Posted: Tue May 30, 2006 6:23 am Post subject: |
|
|
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 |
|
 |
jefflowrey |
Posted: Tue May 30, 2006 6:49 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
|
Back to top |
|
 |
tom_hanks |
Posted: Wed May 31, 2006 12:42 am Post subject: |
|
|
Apprentice
Joined: 19 May 2006 Posts: 32
|
Sure jefflowrey.
I am followinig those references.
thanks a lot.
-Tom |
|
Back to top |
|
 |
|