Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

javax.mail.internet.ParseException  HELP!!!

Posted on 2004-04-27
5
1,212 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
ID: 10928521
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
ID: 10929192
Unfortunately I get the same error.
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 10929421
Instead of

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

try

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

Author Comment

by:bohnman
ID: 10930435
That did it.  Thank you.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10930495
8-)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

789 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