Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

javax.mail Error

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post your code, and we'll try to help you find the problem.
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm moving this to the "other API's" forum where javax.mail is often discussed -- so please post your replies tere. Thanks!
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The location of the .jar files is as specified in the ant file. Is this incorrect?
 
Gerry Morris
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic