?
Solved

javax.mail.internet.ParseException  HELP!!!

Posted on 2004-04-27
5
Medium Priority
?
1,225 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
[X]
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
  • 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
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 will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 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