Saaj and javamail
Hi all,
Am facing the following problem while using JavaMail api to generate mime file.
com.sun.xml.messaging.saaj.soap.XmlDataContentHandler.writeTo(XmlDataContentHandler.java:96)
javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:839)
javax.activation.DataHandler.writeTo(DataHandler.java:295)
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1089)
javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:635)
javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:233)
Actually I have two programs that should run on my machine. One program uses SAAJ api to parse soap with attachments.Along with this i have activation.jar that comes with Sun Appserver.
The other program uses javamail api to generate mime file. the first body part of mime file is an xml file and i set the content type as "text/xml".
Now, when I run the code that uses javamail api, am getting the error...com.sun.xml.messaging.saaj.soap.XmlDataContentHandler.writeTo.... here am not using saaj api in this code...
One observation is, if change the content-type to "text/plain", it works fine. But i want the content type as "text/xml".
I think some conflicts in jar files in classpath is leading to this. Can some please help in figuring out the solution for this.
Thanks in Advance,
Swetha.
IIRC, you just pass in an array like you would any other Object.
Similar Messages
-
Using JSF and JavaMail to send Automated Email
Hi All,
Can any one please suggest I can use JSF and JavaMail to send automated email messages i.e after a person has successfully completed a form , a message is sent to his/her email address confirming that he has succesfully registered or completed a form. I have succesfull implemeted the use of javamail for sending email meassages in a JSF web application but cant seem to figure out how i can achieve automated sending of emails in JSF. Please any ideas, tutorials or source code would be very much appreciated.
Thanks.I don't understand your problem:
You have already been able to send e-mails from a JSF webapplication, but you are not capable of sending e-mails from a JSF webapplication?!
Automated sending of e-mails will be exactly the same as non-automated. -
I have this Javamail program that I know works and I'm trying to put it into JSP. Since I'm still new to JSP, I can't figure out why I'm getting this error:
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
C:\tomcat\work\localhost\ams\index$jsp.java:11: Package javax.mail not found in import.
import javax.mail.*;
^
C:\tomcat\work\localhost\ams\index$jsp.java:12: Package javax.mail.internet not found in import.
import javax.mail.internet.*;
I just can't get the javamail stuff to work in JSP. Could you tell me why?
Thank you in advance,
Mikehmm...no, I have the javamail package on my c:\
This is what my CLASSPATH looks like:
.;C:\ServletDevel;C:\tomcat\common\lib\servlet.jar;C:\javamail-1.2\mail.jar;C:\jaf-1.0.1\activation.jar
Question 1
Should I just change the location of the javamail and jaf folders to:
C:\tomcat\lib or C:\tomcat\common\lib ???
and change the CLASSPATH??
Question 2
or should I just download it again and add to the CLASSPATH rather than change it???? And again, which lib directory? C:\tomcat\lib or C:\tomcat\common\lib ???
Thanks again,
Mike -
Hi,
I have developed an EJB for sending emails using the javamail api.
My problem is that when i run the same code using the a standalone java application (i have pasted the code from the EJB) and try sending mails outside the my companies domain the mails are going.
However when i try sending the mails using the JSP end EJB the mails are not going.
I noticed that in the standalone java application the protected method getPasswordAuthentication gets called by the system. However the same is not getting called in the EJB.
I am new to this technology. Can anyone please help me out here.
I am sending the code also that i am using:-
// Get all the system properties
Properties props = System.getProperties();
props.put("mail.smtp.host", "HOSTNAME");
props.put("mail.smtp.auth", "true");
SetAuthentication auth = new SetAuthentication();
Session session = Session.getInstance(props, auth);
session.setDebug(true);
// Create a message
Message msg = new MimeMessage(session);
try {
// Set the From Address
Address addrFrom =new InternetAddress("[email protected]");
msg.setFrom(addrFrom);
// Set the TO address
Address addrTo = new InternetAddress(strTo);
msg.setRecipient(MimeMessage.RecipientType.TO, addrTo);
// Set the subject of the mail
msg.setSubject(strSubject);
msg.setContent(strContent, "text/plain");
msg.saveChanges();
Transport.send(msg);
// Code in class SetAuthentication
private PasswordAuthentication auth;
public SetAuthentication() {
super();
auth = new PasswordAuthentication("user", "password");
protected PasswordAuthentication getPasswordAuthentication() {
return auth;Hi,
I have worked on JBoss and Weblogic app servers and one can initialize java mail settings in the app server,.I am sorry, i don't know how its done in the app server you are using.
I would suggest you to try the following :
static {
/* Setting Properties for STMP host */
props = System.getProperties();
props.put("mail.smtp.host", "PUT SMTP SERVER HERE");
props.put("mail.smtp.auth", "true");
session = Session.getDefaultInstance(props, null);
try {
MimeMessage message = new MimeMessage(session);
message.setRecipient(Message.RecipientType.TO,
new InternetAddress(this.to));
message.setFrom(new InternetAddress(this.from));
message.setSubject(this.subject);
message.setText(this.message);
Transport transport = session.getTransport("smtp");
transport.connect("PUT SMTP SERVER HERE", "PUT USERNAME HERE", "PUT PASSWORD HERE");
message.saveChanges();
transport.sendMessage(message, message.getAllRecipients());
transport.close();
} catch (MessagingException e) {
throw new Exception(e.getMessage()); -
X.400 instead of SMTP Protocol and Javamail API
We have developed a workflow application on Domino 5.0.7. The SmartHost is "MS Exchange Server", because the application will only be accessed by browsers, we are using javaagent to send the email notifications. Due to some domain restrictions on MS Exhchange servers we have implemented Javamail API on the domino server, and it worked fine (I mean the messages were received by the Exchange Clients, using the SMTP addresses like [email protected]). As we dont have available SMTP addresses for all end users in the company we need to use the X.400 addresses. Is there anyone, can help guide about either the avaiability of any X.400 javamail api, or how to use mapi etc? I know it is little bit challenging, but we are struck. thanks
Currently, the latest version of the JavaMail 1.2 API, X.400 transport protocol is not supported yet. Only the transport SMTP - a message Transport protocol, for sending messages to a server, is supported.
Allen Lai
SUN Developer Technical Support -
HI,
I am using log4j 1.2.8 for logging and I plan to use the SMTPAppender for sending mails of those exceptions.I am using javamail mail.jar version 1.3.
upon execution, i get the following error.
log4j:ERROR Error occured while sending e-mail notification.
javax.mail.NoSuchProviderException: smtp
at javax.mail.Session.getService(Session.java:611)
at javax.mail.Session.getTransport(Session.java:541)
at javax.mail.Session.getTransport(Session.java:484)
at javax.mail.Session.getTransport(Session.java:464)
at javax.mail.Session.getTransport(Session.java:519)
at javax.mail.Transport.send0(Transport.java:155)
at javax.mail.Transport.send(Transport.java:81)
at org.apache.log4j.net.SMTPAppender.sendBuffer(Unknown Source)
at org.apache.log4j.net.SMTPAppender.append(Unknown Source)
at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:221)
at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:57)
at org.apache.log4j.Category.callAppenders(Category.java:187)
at org.apache.log4j.Category.forcedLog(Category.java:372)
at org.apache.log4j.Category.error(Category.java:303)
at com.saterisystems.api_selfcarev1r0.API_getServiceList.logon(API_getServiceList.java:93)
at com.saterisystems.api_selfcarev1r0.API_getServiceList.main(API_getServiceList.java:427)
I have configured the mail server and related stuff in the log4j properties file.
Can anyone help me out please?
Thanks & Regards,
Anand KapadiStart here:
http://java.sun.com/products/javamail/FAQ.html#servletSecurityManager -
Hi there,
can somebody point me in the right direction on how to encode an Array for use with SAAJ. All documentation examples and everything else is just plain simple elements (using addTextNode), which isn't suitable to do a SOAP encoded array.
Any pointers or help is appreciated.
Thanks,
Reiner KappenbergerIIRC, you just pass in an array like you would any other Object.
-
Hi,
I have been trying to send email from my java application through an exchange server about 6 months ago and found this to be impossible. I gave up on that method and have circumvented the issue with success. I send the details of the email to my server, and have my server send the email
But, i was wondering if the javamail API has been upgraded, adapted, change, modified or any other form of alteration to allow emails to be sent through an exchange server????No idea. We're not expert with javamail, as it's really a java application.
We know about Messaging Server, which really has little to do with Java. -
Hello,
I was wondering if somebody ran into performance issues when using JavaMail on an AIX Server. We're running AIX 4.3.3 along with IBM Java 1.3.1.
I have run some tests and found that on the normal workstation (NT box) it had no problems sending the message in fact it took about a second to do that. But once I ported the code over to an AIX server box and ran the same code it took about 13 seconds in sending the same message.
Does anybody have a solution or explanation for this problem? Any help would be appreciated.
Thanks,
NySince you are talking about multiple seconds, try turning on debug mode. Then send a mail and watch what comes up on the console. If there are big pauses, you will be able to see where they occur. Chances are it's a network configuration thing.
-
WebStart and JavaMail -- unable to relay
Hi
I have an application that I can run from the command line that can successfully send email using JavaMail.
I package the app up for WebStart and run it on the same machine, when I send the mail using JavaMail I get a 550 error:
class com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for [email protected];Any ideas? My mail.jar and activation.jar are specified in my JNLP file for my app as an extension (as they are signed already)...
Has anyone seen this?
Thx,
Marker no
I run my app from a command shell on XP and sendimg mail via our Exchange server works fine on my development machine.
I run the SAME app using a WebStart based installation on the same machine as per the command shell run, with the installation downloaded from a webserver on the same machine and when the piece of code that sends a mail is invoked I get the UNable to relay error..
Why would it work from the command shell and not from WebStart...
Mark -
Tomcat and JavaMail Sessions problem
I'm using Tomcat (with struts). I've configured my web application in server.xml to manage JavaMail Sessions:
<Resource name="mail/Session" auth="Container" type="javax.mail.Session"/>
<ResourceParams name="mail/Session">
<parameter>
<name>mail.smtp.host</name>
<value>gandalf</value>
</parameter>
</ResourceParams>
Also, I've configured my web application deployment descriptor (web.xml) to use this resource:
<resource-ref>
<description>JavaMail Resource</description>
<res-ref-name>mail/Session</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Now in the Java code I try to get the JavaMail session in this way:
private Context devuelveContexto() throws javax.naming.NamingException
initContext = new InitialContext();
return (Context) initContext.lookup("java:/comp/env");
public javax.mail.Session devuelveSesionMail()
throws javax.naming.NamingException
Context envContext = devuelveContexto();
javax.mail.Session mailSesion = (javax.mail.Session) envContext.lookup("mail/Session"); <--- this throws an exception
I'm doing all like is explained in Tomcat help web page 'JNDI Resources HOW-TO' but it doesn' work for me.
The exception raised is this:
java.lang.reflect.InvocationTargetException: java.lang.ClassCastException: javax.mail.Session
at com.aplicacionesweb.evaluaciones.ddbb.CargadorRecursos.devuelveSesionMail(CargadorRecursos.java:76)
at com.aplicacionesweb.evaluaciones.fases.actions.ConcertacionAction.enviarCorreo(ConcertacionAction.java:562)
at com.aplicacionesweb.evaluaciones.fases.actions.ConcertacionAction.grabarConcertacion(ConcertacionAction.java:510)
at java.lang.reflect.Method.invoke(Native Method)
at org.apache.struts.actions.DispatchAction.perform(DispatchAction.java:236)
at org.apache.struts.action.ActionServlet.processActionPerform(ActionServlet.java:1787)
Please help.Problem solved. I had 'mail.jar' and 'activation.jar' in 'WEB-INF/lib' directory, causing a classes conflict.
-
AuthenticationFailedException when using JNDI and JavaMail with SMTP auth
Hi all - I've been banging my head on this one for awhile now - hopefully someone else has done this.
We are working in a servlet container (tomcat), and need obtain a mail session from JNDI. We do this as follows:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Session mailSession=(Session) envCtx.lookup("mailSession/trumpetinc");so far so good. The jndi entry for the mail session is configured in server.xml as follows:
<Resource name="mailSession/trumpetinc" scope="Shareable" type="javax.mail.Session"/>
<ResourceParams name="mailSession/trumpetinc">
<parameter>
<name>mail.smtp.host</name>
<value>mail.server.com</value>
</parameter>
<parameter>
<name>mail.smtp.password</name>
<value>ABCDEFG</value>
</parameter>
<parameter>
<name>mail.smtp.user</name>
<value>trumpet_kevin</value>
</parameter>
<parameter>
<name>mail.smtp.auth</name>
<value>true</value>
</parameter>
</ResourceParams>With the above, whenever we hit Transport.send(msg), we got an AuthenticationFailedException thrown. I have run into this before with SMTP authentication, so I decided to try using the transport.sendMessage() method instead.
So, I get the transport:
Transport trans = mailSession.getTransport("smtp");
trans.connect();Then I send my message using:
msg.saveChanges();
trans.sendMessage(msg, msg.getAllRecipients());and finally, I close the transport:
trans.close();Unfortunately, I'm still getting the exception. Is it possible that my connect() method is not picking up the JNDI properties set in the server.xml file (this seems likely)? If so, what's the best way for me to get those properties so I can set them explicitly in the connect() method?
Thanks in advance,
- KevinHi,
I have faced the same problem and after some googling and trying I have discovered what causes the AuthenticationFailedException exception. I just wanted to share the knowedge maybe it will be helpfull to others.
Here it is what the API says:
To use SMTP authentication you'll need to set the mail.smtp.auth property (see below) and provide the SMTP Transport with a username and password when connecting to the SMTP server. You can do this using one of the following approaches:
1.Provide an Authenticator object when creating your mail Session and provide the username and password information during the Authenticator callback.
Note that the mail.smtp.user property can be set to provide a default username for the callback, but the password will still need to be supplied explicitly.
This approach allows you to use the static Transport send method to send messages.
2.Call the Transport connect method explicitly with username and password arguments.
This approach requires you to explicitly manage a Transport object and use the Transport sendMessage method to send the message. The transport.java demo program demonstrates how to manage a Transport object. The following is roughly equivalent to the static Transport send method, but supplies the needed username and password:
Using the Transport.connect makes the JNDI not very helpfull for configuration.
It seems that using just the mail.smtp.user and mail.smtp.pass is not sufficient for the authentication.
so, the solution is :
just place these to lines in the JNDI configuration:
username="test"
password="test1"
so it should looks as follows:
<Resource name="mail/Session" auth="Container"
type="javax.mail.Session"
username="test"
password="test1"
mail.transport.protocol="smtp"
mail.smtp.auth="true"
mail.smtp.host="localhost"
mail.smtp.port="25"
mail.smtp.user="test"
mail.smtp.password="test1"
/>
where test and test1 are the user's credentials
Regards,
Kiril
Message was edited by:
Kireto
Message was edited by:
Kireto -
Hi,
I am having a problem in running SAAJ client for Axis running on Tomcat. My SAAJ code is as follows;
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnectionFactory.createConnection();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPBody body = message.getSOAPBody();
header.detachNode();
QName bodyName = new QName("http://localhost/axis2/services/SoapService",
"mymethod", "m");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
QName name = new QName("vinput");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("12667");
URL endpoint = new URL("http://localhost/axis2/services/SoapService/mymethod");
SOAPMessage sresponse = connection.call(message, endpoint);
connection.close(); However I am getting runtime errors like this;
SEVERE: Exception occurred while trying to invoke service method mymethod
org.apache.axis2.AxisFault: namespace mismatch require http://localhost/xsd found http://localhost/axis2/services/SoapService
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:103)
at org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver.receive(AbstractInOutSyncMessageReceiver.java:39)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:144)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest( My WEB-INF/services.xml is like this;
<service name="SoapService" scope="application">
<description>RME Soap Service</description>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</messageReceivers>
<schema schemaNamespace="http://localhost/axis2/services/SoapService?xsd" />
<parameter name="ServiceClass">SoapService</parameter>
</service> Could you tell me how this thing work? Especially how to specify namespace in different parts! This works fine if I use browser URLs!
Thanks in advance.I solved this problem. It was related to namespace!
-
hi,
i'm planning to user javamail for a project i'm working on, on an iplanet server, i have already downloaded the mail.jar file, but do not know where to put it on the server, or what to configure to use it, does anyone know?
Thank you.hi,
i'm planning to user javamail for a project i'm
working on, on an iplanet server, i have already
downloaded the mail.jar file, but do not know where to
put it on the server, or what to configure to use it,
does anyone know?
Thank you.Dear Soni,
I am facing some problem in sending e-mail from a servlet using iPlanet 6.0 on Windows ,jdk1.3.Can u pls help me asap??Can I have ur mail id so that I can get in touch with u regading this problem??My mail id is [email protected] help asap.
Thanx in advance.
prasanna -
Javamail and bad file names in attachment
Hi all,
We are having an issue interpretting bad filenames are
in the attachments of emails received. Our application
listens to an inbox and then interprets the messages
in the inbox.We copy the attachment to the local
machine.Now some email attachments come with bad names
like with accents or japanese/chinese characters and
javamail is not able to interpret thses characters.
part.getFilename returns some weird symbols and
sometimes ?=iso-...... I tried using the decodeText
method and this does not seem to work. Infact using
this results in some good filenames being converted to
bad names. Please let me know how to go about fixing
this issue.
I really appreciate your help.
Thanks,can you send your code for receving & sending attachment
so that i can help you
Maybe you are looking for
-
Logical Sys Name for Business system in SLD for Third Party
Hi !! I have little doubt what will be the logical system name for creating Business systems in SLD for third party? thanks Gowri
-
Itunes has stopped working vista ultimate
Hi All, I am using Vista ultimate 32bit fully updated and have itunes 7.6 installed. Each time I open itunes an error appears saying itunes has stopped working. Itunes 7.5 was like this but occasionally did open, however 7.6 just refuses to open at a
-
Extracting package and procedure name in code
In my exception processing I need to log the package and procedure name that got the exception. How do I obtain these two names without manually coding the names? Thanks in anticipiation
-
Dear ALl, While creating PO one GL account is picked up automatically,Where that GL is used to maintained and where in Material Management is assign with. Regards, Rita
-
How to setup FAX Alert CCMS MTE
Hi, I would like to know how to setup fax alert, for example if fax does not work, so what is MTE will I use for fax alert all others alerts are working fine and i received e mail , how do I receive e mail if fax does not working... ? Thanks