This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Other JSE/JEE APIs and the fly likes javax.mail Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "javax.mail Error" Watch "javax.mail Error" New topic

javax.mail Error

benny rusli
Ranch Hand

Joined: Jan 15, 2005
Posts: 72
Hallo everybody,
i created a send E-mail with javax.mail package, and got the following error : javax.mail.internet.AddressException : Illegaladdress in string ``��
Can someone explain me what should i do, i give the correct data for the E-mail sending.
Tom Blough
Ranch Hand

Joined: Jul 31, 2003
Posts: 263
Post your code, and we'll try to help you find the problem.

Tom Blough<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr>Cum catapultae proscriptae erunt tum soli proscripti catapultas habebunt.<hr></blockquote>
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

I'm moving this to the "other API's" forum where javax.mail is often discussed -- so please post your replies tere. Thanks!
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Looks like you are trying to send a message with an invalid address. As Tom Bough writes - you could post your code, and perhaps someone can spot why.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Gerry Morris

Joined: Mar 16, 2005
Posts: 10
I am a newbie having problems with javax.mail as well. Am developing on WinXpsp2 machine with j2sdk1.4.2_04. Anyway, I am trying to write a simple mail program using the following example code:

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class HelloMail {
public static void main(String args[]) throws Exception {
String host=""; //your smtp host
String from=""; //sender's email
String to ="" ; //receiver's email

Properties props = System.getProperties();
props.put("", host);

Session session=Session.getInstance(props,null);

MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(" My Test email ");
message.setText(" Here is the content ");
Transport transport = session.getTransport("smtp");
Here is the ant script I am using to compile:

<project name="Generic Webapp" default="compile" basedir=".">
<target name="compile" description="Compile Java sources" >

Everything compiles fine. However, when I go to run it I get the following message : "Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Address". I have been to every BB and devel site and have tried many different things and nothing seems to work.

Does anyone have a suggestion? Any and all help will be greatly appreciated.
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Looks like your classpath is wrong, and the classloader can't find mail.jar. Try running Ant with the -verbose flag, this will show you where Javac is trying to load specific jars from.
Gerry Morris

Joined: Mar 16, 2005
Posts: 10
The location of the .jar files is as specified in the ant file. Is this incorrect?
Gerry Morris

Joined: Mar 16, 2005
Posts: 10
BTW, here is the ant output:

$ ant -verbose
Apache Ant version 1.6.2 compiled on July 16 2004
Buildfile: build.xml
Detected Java version: 1.4 in: c:\j2sdk1.4.2_04\jre
Detected OS: Windows XP
parsing buildfile C:\projects\test\build.xml with URI = file:///C:/projects/test
Project base dir set to: C:\projects\test
Build sequence for target `compile' is [compile]
Complete build sequence is [compile, ]

[javac] added as HelloMail.class doesn't exist.
[javac] Compiling 1 source file to C:\projects\test\bin
[javac] Using modern compiler
[javac] Compilation arguments:
[javac] '-d'
[javac] 'C:\projects\test\bin'
[javac] '-classpath'
[javac] 'C:\projects\test\bin;C:\projects\test;C:\projects\test\src;C:\proje
[javac] '-sourcepath'
[javac] 'C:\projects\test\src'
[javac] '-g:none'
[javac] The ' characters around the executable and arguments are
[javac] not part of the command.
[javac] File to be compiled:
[javac] C:\projects\test\src\

Total time: 4 seconds
Gerry Morris

Joined: Mar 16, 2005
Posts: 10
AAAArgh!! I solved the problem. I discovered that if I use the -classpath option when I run the script ($ java -classpath ".;./src;../lib/mail.jar;../lib/activation.jar;" HelloMail) it runs correctly. So maybe that is what you were referring to. I was under the assumption that somehow when you compiled into a class that the location of the .jar files were magically associated. Guess it's true what they say about assuming...... Anyway, thanks for the help!!!
I agree. Here's the link:
subject: javax.mail Error
jQuery in Action, 3rd edition