| Author |
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
Sheriff
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
Bartender
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
Greenhorn
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.host.here"; //your smtp host String from="from@address.here"; //sender's email String to ="to@address.here" ; //receiver's email Properties props = System.getProperties(); props.put("mail.smtp.host", 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"); transport.connect(host,"uname","pswd"); transport.send(message); } } ------------------------------------------ Here is the ant script I am using to compile: ------------------------------------------- <project name="Generic Webapp" default="compile" basedir="."> <target name="compile" description="Compile Java sources" > <javac srcdir="src" destdir="bin" debug="false" deprecation="off" classpath=".;./src;./lib/mail.jar;./lib/activation.jar;./bin;" /> </target> </project> ------------------------------------------- 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
Bartender
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
Greenhorn
Joined: Mar 16, 2005
Posts: 10
|
|
|
The location of the .jar files is as specified in the ant file. Is this incorrect?
|
 |
Gerry Morris
Greenhorn
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 /build.xml Project base dir set to: C:\projects\test Build sequence for target `compile' is [compile] Complete build sequence is [compile, ] compile: [javac] HelloMail.java 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 cts\test\lib\mail.jar;C:\projects\test\lib\activation.jar;C:\javadev\apache-ant- 1.6.2\lib\xml-apis.jar;C:\javadev\apache-ant-1.6.2\lib\xercesImpl.jar;C:\javadev \apache-ant-1.6.2\lib\jsch-0.1.18.jar;C:\javadev\apache-ant-1.6.2\lib\ant.jar;C: \javadev\apache-ant-1.6.2\lib\ant-xslp.jar;C:\javadev\apache-ant-1.6.2\lib\ant-x alan1.jar;C:\javadev\apache-ant-1.6.2\lib\ant-weblogic.jar;C:\javadev\apache-ant -1.6.2\lib\ant-vaj.jar;C:\javadev\apache-ant-1.6.2\lib\ant-trax.jar;C:\javadev\a pache-ant-1.6.2\lib\ant-swing.jar;C:\javadev\apache-ant-1.6.2\lib\ant-stylebook. jar;C:\javadev\apache-ant-1.6.2\lib\ant-starteam.jar;C:\javadev\apache-ant-1.6.2 \lib\ant-nodeps.jar;C:\javadev\apache-ant-1.6.2\lib\ant-netrexx.jar;C:\javadev\a pache-ant-1.6.2\lib\ant-launcher.jar;C:\javadev\apache-ant-1.6.2\lib\ant-junit.j ar;C:\javadev\apache-ant-1.6.2\lib\ant-jsch.jar;C:\javadev\apache-ant-1.6.2\lib\ ant-jmf.jar;C:\javadev\apache-ant-1.6.2\lib\ant-jdepend.jar;C:\javadev\apache-an t-1.6.2\lib\ant-javamail.jar;C:\javadev\apache-ant-1.6.2\lib\ant-jai.jar;C:\java dev\apache-ant-1.6.2\lib\ant-icontract.jar;C:\javadev\apache-ant-1.6.2\lib\ant-c ommons-net.jar;C:\javadev\apache-ant-1.6.2\lib\ant-commons-logging.jar;C:\javade v\apache-ant-1.6.2\lib\ant-apache-resolver.jar;C:\javadev\apache-ant-1.6.2\lib\a nt-apache-regexp.jar;C:\javadev\apache-ant-1.6.2\lib\ant-apache-oro.jar;C:\javad ev\apache-ant-1.6.2\lib\ant-apache-log4j.jar;C:\javadev\apache-ant-1.6.2\lib\ant -apache-bsf.jar;C:\javadev\apache-ant-1.6.2\lib\ant-apache-bcel.jar;C:\javadev\a pache-ant-1.6.2\lib\ant-antlr.jar;C:\j2sdk1.4.2_04\lib\tools.jar' [javac] '-sourcepath' [javac] 'C:\projects\test\src' [javac] '-g:none' [javac] [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\HelloMail.java BUILD SUCCESSFUL Total time: 4 seconds
|
 |
Gerry Morris
Greenhorn
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!!!
|
 |
 |
|
|
subject: javax.mail Error
|
|
|