• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1247
  • Last Modified:

javax.mail.internet.ParseException HELP!!!

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
bohnman
Asked:
bohnman
  • 3
  • 2
1 Solution
 
CEHJCommented:
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
 
bohnmanAuthor Commented:
Unfortunately I get the same error.
0
 
CEHJCommented:
Instead of

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

try

message.setContent(text, "text/plain");
0
 
bohnmanAuthor Commented:
That did it.  Thank you.
0
 
CEHJCommented:
8-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now