Solved

javax.mail.internet.ParseException  HELP!!!

Posted on 2004-04-27
5
1,198 Views
Last Modified: 2007-12-19
I am dying here.  Please someone help me figure out why I am getting a ParseException.

Thanxs

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;
import javax.activation.*;

public class Mailer extends HttpServlet {
      private final String MAIL_HOST = "xxxx.xxxx.ibm.com";

      public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
            res.setContentType("text/html");
            PrintWriter out = res.getWriter();

//            String from = req.getParameter("from");
//            String to = req.getParameter("to");
//            String subject = req.getParameter("subject");
//            String text = req.getParameter("text");
            
            String from = "test@us.ibm.com";
            String to = "test1@us.ibm.com";
            String subject = "RE: Testing";
            String text = "This is boring";
            Address[] print;

            Properties prop = System.getProperties();
            prop.put("mail.smtp.host", MAIL_HOST);
            prop.put("mail.from", from);
            Session session = Session.getInstance(prop, null);
            try {
                  Message message = new MimeMessage(session);
                  InternetAddress address[] = { new InternetAddress(to)};
                  message.setRecipients(Message.RecipientType.TO, address);
                  message.setFrom(new InternetAddress(from));
                  message.setSubject(subject);
                  message.setContent("text/plain", text);
                  Transport transport = session.getTransport(address[0]);
                  transport.addConnectionListener(new ConnectionHandler());
                  transport.addTransportListener(new TransportHandler());
                  transport.connect();
                  transport.sendMessage(message, address);
            } catch (Exception ex) {
                  System.out.println(ex);
                  System.out.println(ex.getMessage());
                  ex.printStackTrace();
            }
      }

      class ConnectionHandler extends ConnectionAdapter {
            public void opened(ConnectionEvent ce) {
                  System.out.println("Connection Opened");
            }

            public void disconnected(ConnectionEvent ce) {
                  System.out.println("Connection disconnected");
            }

            public void closed(ConnectionEvent ce) {
                  System.out.println("Connection closed");
            }
      }

      class TransportHandler extends TransportAdapter {
            public void messageTransferred(TransportEvent te) {
                  System.out.println("Message Delivered");
            }

            public void messagePartiallyTransferred(TransportEvent te) {
                  System.out.println("Message Partially Transferred");
            }

            public void messageNotTransferred(TransportEvent te) {
                  System.out.println("Message Not Transferred");
            }
      }

}

The error output is
javax.mail.internet.ParseException
That is it.  There is nothing informative in the error message or stack trace.

[4/27/04 9:09:42:532 EDT]  1a5e0b6 SystemOut     O Connection Opened
[4/27/04 9:09:42:612 EDT] 5649e0b5 SystemOut     O javax.mail.internet.ParseException
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemOut     O
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R javax.mail.internet.ParseException
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R       at javax.mail.internet.ContentType.<init>(ContentType.java:72)
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R       at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1016)
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R       at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:1841)
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R       at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1822)
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R       at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1524)
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R       at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:321)
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R       at Mailer.doGet(Mailer.java:47)
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R       at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R       at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
[4/27/04 9:09:42:622 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:923)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:528)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:201)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:516)
[4/27/04 9:09:42:632 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:362)
[4/27/04 9:09:42:642 EDT] 5649e0b5 SystemErr     R       at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))
0
Comment
Question by:bohnman
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Try deleting all temporary/cached files from your working directory of your container and then recycling it. Then try that code again and let us know the outcome
0
 

Author Comment

by:bohnman
Comment Utility
Unfortunately I get the same error.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
Comment Utility
Instead of

>>message.setContent("text/plain", text);

try

message.setContent(text, "text/plain");
0
 

Author Comment

by:bohnman
Comment Utility
That did it.  Thank you.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
8-)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now