Discussion:
[Classpathx-javamail] Exception while sending mail through GNU JavaMail API.
Dhaval Yoganandi
2009-12-07 08:58:37 UTC
Permalink
Hello gnu javamail team,

I've one problem while sending mail using gnu javamail library. Here is
what I'm using.

I'm using JamVm (a third party java virtual machine) with GNU Classpath
0.98. And I'm also using GNU javamail 1.1.2 library compiled with
dependent GNU libraries. Now, I've written a code to send the stored EML
files on the disk to the recipient. See the following code.

|Authenticator authenticator=||*null*;|

| MailcapCommandMap mc =
(MailcapCommandMap)CommandMap./getDefaultCommandMap/();|

| CommandMap./setDefaultCommandMap/(mc); |

| |

| Properties mailProperties = *new* Properties(); |

| mailProperties.put(MailConstants./MAILSMTPHOST/,
mailServerHost);|

| mailProperties.put(MailConstants./MAILSMTPPORT/,
mailServerPort);|

| mailProperties.put(MailConstants./MAILDEBUG/,
MailConstants./VALUETRUE/);|

|
mailProperties.put(MailConstants./MAILTRANSPORTPROTOCOL/,
MailConstants./TRANSPORTPROTOCOLSMTP/); |

| mailProperties.put(MailConstants./MAILSMTPAUTH/,
"false");|

| mailProperties.put(MailConstants./MAILDEBUG/,
MailConstants./VALUETRUE/);|

| Session mailSession =
Session./getInstance/(mailProperties, authenticator);|

| InputStream source = *new* FileInputStream(file);|

| MimeMessage mimeMessage = *new*
MimeMessage(mailSession,source);|

| mimeMessage.setHeader("Content-Type",
"multipart/mixed");|

| Address[] fromAddrsss = *new* Address[1];|

| Address[] toAddress = *new* Address[1];|

| fromAddrsss[0] = *new* InternetAddress(mailFrom);|

| toAddress[0] = *new*
InternetAddress(mailTo); |

| mimeMessage.addFrom(fromAddrsss);|

| mimeMessage.setRecipients(Message.RecipientType./TO/,
toAddress);|

| mimeMessage.setSubject(strSubject); |

| Transport./send/(mimeMessage);|


and I am getting following exception while sending the mail. The code is
working fine with sun JVM and the javamail (not GNU javamail) library.

Exception is

Exception while sending Mail java.lang.ClassCastException
<http://java.sun.com/javase/6/docs/api/java/lang/ClassCastException.html>:
java/io/ByteArrayInputStreamjava.lang.ClassCastException:
java/io/ByteArrayInputStream

at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:1866)

at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1843)

at javax.mail.Transport.send(Transport.java:74)

at my.utilities.SendUtility.sendMail(SendUtility.java:199)

at my.utilities.SendUtility.handleReleaseRequest(SendUtility.java:70)

at my.servlets.MyServlet.doPost(MyServlet..java:129)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:638)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:720)

at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:199)


at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:145)


at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)


at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)


at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)

at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:139)


at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)


at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)

at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2460)

at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)


at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)


at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:119)


at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)


at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)


at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)


at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)

at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)


at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)


at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:955)

at org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:410)

at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:529)

at java.lang.Thread.run(Thread.java:745)
--
Thanks and Regards,

Dhaval Yoganandi,
Jr. Software Engineer,
Elitecore Technologies Ltd.
Cyberoam.
Chris Burdess
2009-12-08 11:29:30 UTC
Permalink
Post by Dhaval Yoganandi
| InputStream source = *new* FileInputStream(file);|
| MimeMessage mimeMessage = *new* MimeMessage(mailSession,source);|
| mimeMessage.setHeader("Content-Type", "multipart/mixed");|
| Transport./send/(mimeMessage);|
and I am getting following exception while sending the mail. The code is working fine with sun JVM and the javamail (not GNU javamail) library.
This bug is now fixed in CVS HEAD.
--
Chris Burdess
Loading...