Solved

javax.mail.internet.ParseException  HELP!!!

Posted on 2004-04-27
5
1,205 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
reasons why a "inside Menu" would not appear for a web server 6 56
eclipse formatting 6 73
reverse digits of a number using for loop 5 36
MySqlDump not dumping triggers 1 19
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.

867 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

21 Experts available now in Live!

Get 1:1 Help Now